public JsonResult FoodSelect(FoodRegistrationViewModel model) { Response response; try { using (var db = new KiaGalleryContext()) { if (model.id > 0 && model.id != null) { var entity = db.FoodRegistration.Where(x => x.Id == model.id).SingleOrDefault(); entity.FoodCensusId = model.foodCensusId; entity.FoodStatus = model.foodStatus; entity.Appertizer = model.appertizer; entity.Food = model.food; entity.FoodWithoutRice = model.foodWithoutRice; entity.ModifyUserId = GetAuthenticatedUserId(); entity.ModifyDate = DateTime.Now; entity.Ip = Request.UserHostAddress; } else { var item = new FoodRegistration() { FoodCensusId = model.foodCensusId, UserId = GetAuthenticatedUserId(), FoodStatus = model.foodStatus, Appertizer = model.appertizer, Food = model.food, FoodWithoutRice = model.foodWithoutRice, Date = DateUtility.GetDateTime(model.date), CreateUserId = GetAuthenticatedUserId(), ModifyUserId = GetAuthenticatedUserId(), CreateDate = DateTime.Now, ModifyDate = DateTime.Now, Ip = Request.UserHostAddress, }; db.FoodRegistration.Add(item); } db.SaveChanges(); } response = new Response() { status = 200, message = "ثبت اطلاعات با موفقیت انجام شد.", }; } catch (Exception ex) { response = Core.GetExceptionResponse(ex); } return(Json(response, JsonRequestBehavior.AllowGet)); }
public JsonResult SetFood(FoodDateViewModel model) { Response response; try { var userId = GetAuthenticatedUserId(); var selectedDate = DateUtility.GetDateTime(model.date); using (var db = new KiaGalleryContext()) { var food = db.FoodRegistration.Where(x => x.FoodCensus.Date == selectedDate && x.UserId == model.userId && x.FoodCensusId == model.id).SingleOrDefault(); if (food != null) { food.Food = model.food; food.Date = selectedDate; food.FoodStatus = 0; food.ModifyUserId = userId; food.ModifyDate = DateTime.Now; food.Ip = Request.UserHostAddress; } else { var item = new FoodRegistration() { Food = model.food, UserId = model.userId.Value, FoodCensusId = model.id.Value, Date = DateUtility.GetDateTime(model.date), FoodStatus = 0, CreateUserId = userId, ModifyUserId = userId, CreateDate = DateTime.Now, ModifyDate = DateTime.Now, Ip = Request.UserHostAddress, }; db.FoodRegistration.Add(item); } db.SaveChanges(); } response = new Response() { status = 200, }; } catch (Exception ex) { response = Core.GetExceptionResponse(ex); } return(Json(response, JsonRequestBehavior.AllowGet)); }