Esempio n. 1
0
        public JsonResult AddDetailsLookup(DetailsLookupViewModel DetailsLookupViewModel)
        {
            try
            {
                int languageId    = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]);
                var DetailsLookup = new DetailsLookup
                {
                    CreatedOn = DateTime.Now,
                    CreatedBy = User.Identity.Name,
                    Status    = DetailsLookupViewModel.Status,
                    MasterId  = DetailsLookupViewModel.MasterId,
                };
                _db.DetailsLookups.Add(DetailsLookup);
                _db.SaveChanges();

                var detailsLookupTran = new DetailsLookupTranslation()
                {
                    Value           = DetailsLookupViewModel.Name,
                    LanguageId      = languageId,
                    IsDefault       = languageId == CultureHelper.GetDefaultLanguageId(),
                    DetailsLookupId = DetailsLookup.Id,
                };
                _db.DetailsLookupTranslations.Add(detailsLookupTran);

                if (!detailsLookupTran.IsDefault)
                {
                    var detailsLookupTran1 = new DetailsLookupTranslation()
                    {
                        Value           = DetailsLookupViewModel.Name,
                        LanguageId      = CultureHelper.GetDefaultLanguageId(),
                        IsDefault       = true,
                        DetailsLookupId = DetailsLookup.Id
                    };
                    _db.DetailsLookupTranslations.Add(detailsLookupTran1);
                }
                _db.SaveChanges();

                DetailsLookupViewModel.Id = DetailsLookup.Id;
                return(Json(DetailsLookupViewModel, JsonRequestBehavior.AllowGet));
            }

            catch (Exception ex)
            {
                LogHelper.LogException(User.Identity.Name, ex, "Error while add Details lookup");
                return(null);
            }
        }
Esempio n. 2
0
        public ActionResult EditDetailsLookup(DetailsLookupViewModel DetailsLookupViewModel)
        {
            try
            {
                var detailsLookup = _db.DetailsLookups.Find(DetailsLookupViewModel.Id);
                if (detailsLookup != null && detailsLookup.Status != (int)GeneralEnums.StatusEnum.Deleted)
                {
                    detailsLookup.Status           = DetailsLookupViewModel.Status;
                    _db.Entry(detailsLookup).State = EntityState.Modified;
                    _db.SaveChanges();

                    var DetailsTran = _db.DetailsLookupTranslations.FirstOrDefault(r => r.LanguageId == DetailsLookupViewModel.LanguageId && r.DetailsLookupId == DetailsLookupViewModel.Id);
                    if (DetailsTran != null)
                    {
                        DetailsTran.Value            = DetailsLookupViewModel.Name;
                        _db.Entry(DetailsTran).State = EntityState.Modified;
                    }
                    else
                    {
                        var detailsLookupTran = new DetailsLookupTranslation()
                        {
                            Value           = DetailsLookupViewModel.Name,
                            LanguageId      = DetailsLookupViewModel.LanguageId,
                            IsDefault       = false,
                            DetailsLookupId = detailsLookup.Id
                        };
                        _db.DetailsLookupTranslations.Add(detailsLookupTran);
                    }
                    _db.SaveChanges();
                }

                return(Json(DetailsLookupViewModel, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                LogHelper.LogException(User.Identity.Name, ex, "Error While Editing Details Lookup (Get)");
                return(null);
            }
        }