Save information from tabs

Asked

Viewed 58 times

0

I have my canvas, as follows: inserir a descrição da imagem aqui

each tab corresponds to a class, and database entity, and going in sequence there is a reference to them, ie

na 02 tem referencia(fk) da 01, na 03 tem referencia(fk) 02 and so on.

I until then always saved and returned the saved id for when change tab he have id(fk) and can save.

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

Can someone give me an idea of how to fix this?

Can be using Angularjs

1 answer

1

If your models wear Guids, the solution becomes natural.

Suppose the following models:

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 main model already exists, you use a temporary key to reference in 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 all at the discretion of the programmer. The bank only receives the information. There is no concern with primary key generation IDENTITY and no need to work with temporary keys.

When it comes to saving a single SaveChanges() does everything.

Now, if your models use primary keys int with IDENTITY, you will have save the main registration already in the first tab change, along with the first tab registration, unless the user cancels the action already in the first tab. I consider that for a system using Angularjs this is very bad.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.