Exemple #1
0
 public FamiliaViewModel DomainToViewmodel(TbPrFamilia domain)
 {
     return(new FamiliaViewModel
     {
         Descripcion = domain.Descripcion,
         IdFamilia = (int?)domain.IdFamilia,
         FechaCreacion = domain.FechaCreacion,
         IdUsuario = (int)domain.IdUsuario,
         Id = (int)domain.Id
     });
 }
Exemple #2
0
        public ActionResult CrearEditarFamilia(int id, FamiliaViewModel viewModel)
        {
            try
            {
                var familia = new TbPrFamilia();
                var edita   = false;

                var existeFamilia = service.GetFamiliaByDescripcion(viewModel.Descripcion);

                if (id == 0)
                {
                    if (existeFamilia != null)
                    {
                        return(Json(new { success = false }));
                    }

                    viewModel.IdUsuario = int.Parse(User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value);
                    familia             = map.Create(viewModel);
                }
                else
                {
                    if (existeFamilia != null)
                    {
                        if (existeFamilia.Id != id)
                        {
                            return(Json(new { success = false }));
                        }
                    }

                    familia = map.Update(id, viewModel);
                    edita   = true;
                }

                familia.IdFamiliaNavigation = null;
                foreach (var item in familia.InverseIdFamiliaNavigation)
                {
                    item.IdFamiliaNavigation = null;
                }


                return(Json(new { success = true, familia = familia, edita = edita }));
            }
            catch (Exception ex)
            {
                AltivaLog.Log.Insertar(ex.ToString(), "Error");
                return(Json(new { data = false }));;
            }
        }
        public ActionResult CrearEditarFamilia(int id, FamiliaViewModel viewModel)
        {
            try
            {
                var familia = new TbPrFamilia();
                if (id == 0)
                {
                    viewModel.IdUsuario = int.Parse(User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value);
                    familia             = map.Create(viewModel);
                }
                else
                {
                    familia = map.Update(id, viewModel);
                }

                return(Json(new { descripcion = familia.Descripcion, id = familia.Id }));
            }
            catch
            {
                //throw;
                return(Json(new { data = false }));;
            }
        }
Exemple #4
0
 public bool Delete(TbPrFamilia domain)
 {
     return(repository.Delete(domain));
 }
Exemple #5
0
 public TbPrFamilia Update(TbPrFamilia domain)
 {
     return(repository.Update(domain));
 }
Exemple #6
0
 public TbPrFamilia Save(TbPrFamilia domain)
 {
     return(repository.Save(domain));
 }