Save tab information

0

I have my screen, as follows:

Each tab corresponds to a class, and database entity, and going in the sequence there is a reference of them, that is to say

in 02 has reference (fk) of 01, in 03 has reference (fk) 02 and so on.

I've always saved and returned the saved id so that when I change the tab it has the id (fk) and I can save it.

However, if the user cancels, there would be a vacant registry, besides he can not skip the tabs, he has to always go in sequence.

Can anyone give me an idea how to solve this?

You can use angularjs

    
asked by anonymous 27.06.2014 / 15:35

1 answer

1

If your templates use Guids , the solution becomes natural.

Suppose the following templates:

public class ModeloPrincipal
{
    [Key]
    public Guid ModeloPrincipalId {get; set; }
}

public class ModeloAba1
{
    [Key]
    public Guid ModeloAba1Id {get; set; }
    public Guid ModeloPrincipalId {get; set; }

    public virtual ModeloPrincipal ModeloPrincipal { get; set; }
}

public class ModeloAba2
{
    [Key]
    public Guid ModeloAba2Id {get; set; }
    public Guid ModeloPrincipalId {get; set; }

    public virtual ModeloPrincipal ModeloPrincipal { get; set; }
}

public class ModeloAba3
{
    [Key]
    public Guid ModeloAba3Id {get; set; }
    public Guid ModeloPrincipalId {get; set; }

    public virtual ModeloPrincipal ModeloPrincipal { get; set; }
}

When the parent template already exists, you use a temporary key to reference the creation:

public ActionResult Create() 
{
    var modeloPrincipal = new ModeloPrincipal();
    modeloPrincipal.ModeloPrincipalId = Guid.NewGuid();

    modeloPrincipal.ModeloAba1 = new ModeloAba1 {
        modeloPrincipalId = modeloPrincipal.ModeloPrincipalId;
    };

    modeloPrincipal.ModeloAba2 = new ModeloAba2 {
        modeloPrincipalId = modeloPrincipal.ModeloPrincipalId;
    };

    modeloPrincipal.ModeloAba3 = new ModeloAba4 {
        modeloPrincipalId = modeloPrincipal.ModeloPrincipalId;
    };

    return View(modeloPrincipal);
}

The generation of the keys is entirely at the discretion of the programmer. The bank only receives the information. There is no concern with primary key generation IDENTITY and there is no need to work with temporary keys.

When saving, a single SaveChanges() does everything.

Now, if your models use int primary keys with IDENTITY , you'll have to save the master record already on the first tab change, along with the first tab record, unless the user cancels the action already in the first tab. I think for a system using AngularJS this is pretty bad.

    
27.06.2014 / 19:36