public ActionResult AddItem(Item objitem) { var status = "error"; try { if (!Authenticated) { status = "SESSION EXPIRED"; } else if (objitem.SalePrice < objitem.CostPrice) { status = "costgreaterthansale"; } else { var objExist = db.Items.Where(x => x.Name == objitem.Name && x.CategoryId == objitem.CategoryId && x.SubCategoryId == objitem.SubCategoryId).ToList(); if (objExist.Count < 1) { objExist = null; } if (objExist == null) { if (objitem.IsActive == null) { objitem.IsActive = false; } if (objitem.SubCategoryId == 0 || objitem.SubCategoryId == null) { objitem.SubCategoryId = null; } objitem.UID = Guid.NewGuid(); objitem.CreatedBy = ActiveUserId; objitem.CreatedOn = DateTime.Now; db.Items.Add(objitem); if (db.SaveChanges() > 0) { var item = db.GetItemByUID(objitem.UID); status = JsonConvert.SerializeObject(item); //Assigned true to size ,uom and color that use in this item var objSize = db.Sizes.Where(x => x.Id == objitem.SizeId).SingleOrDefault(); var objUom = db.UnitOfMeasures.Where(x => x.Id == objitem.UomId).SingleOrDefault(); var objColor = db.Colors.Where(x => x.Id == objitem.ColorId).SingleOrDefault(); var objCategory = db.Categories.Where(x => x.Id == objitem.CategoryId).SingleOrDefault(); var objSubCategory = db.SubCategories.Where(x => x.Id == objitem.SubCategoryId).SingleOrDefault(); objSize.IsAssigned = true; objUom.IsAssigned = true; objColor.IsAssigned = true; objCategory.IsAssigned = true; objSubCategory.IsAssigned = true; db.SaveChanges(); } } else { status = "exist"; } } } catch (Exception ex) { ApplicationExceptionLogging(ex.Message, ex.StackTrace, "ItemManagementController", "AddItem"); } return(Content(status)); }