ActionOutput IMotherManager.UpdateMotherDishDailySchedule(List <MotherDishScheduleModel> model) { ActionOutput res = new ActionOutput(); try { int UserId = model.FirstOrDefault().UserId; var dishsch = (from p in Context.MotherDishDailySchedules join m in Context.MotherDishes on p.MotherDishId equals(m.Id) join mo in Context.MotherTbls on m.MotherId equals(mo.Id) where mo.UserId == UserId && p.Date == DateTime.Now select p).ToList(); if (dishsch.Count <= 0) { var MotherDetails = Context.MotherTbls.Where(p => p.UserId == UserId).FirstOrDefault(); if (MotherDetails != null) { List <MotherDishDailySchedule> list = new List <MotherDishDailySchedule>(); foreach (var item in model) { MotherDishDailySchedule mdds = new MotherDishDailySchedule(); mdds.Availabilty = item.Availabilty; mdds.Date = item.Date; mdds.MotherDishId = item.MotherDishId; mdds.Quantity = item.Quantity; mdds.Type = item.Type; list.Add(mdds); } Context.MotherDishDailySchedules.AddRange(list); Context.SaveChanges(); res.Status = ActionStatus.Successfull; res.Message = "Mother's Daily Dish Scheduled updated Successfully."; } else { res.Status = ActionStatus.Error; res.Message = "Mother doesn't exists"; } } else { foreach (var item in dishsch) { var partdata = model.Where(p => p.MotherDishId == item.MotherDishId).FirstOrDefault(); if (partdata != null) { item.Availabilty = partdata.Availabilty; item.Date = partdata.Date; item.Quantity = partdata.Quantity; item.Type = partdata.Type; } } Context.SaveChanges(); res.Status = ActionStatus.Successfull; res.Message = "Mother's Daily Dish Schedule updated Successfully."; } } catch (Exception ex) { res.Status = ActionStatus.Error; res.Message = "Some Error Occurred"; } return(res); }
public MotherDishScheduleModel(MotherDishDailySchedule obj) { this.Id = obj.Id; this.Availabilty = obj.Availabilty; this.Date = obj.Date; this.MotherDishId = obj.MotherDishId; this.Quantity = obj.Quantity; this.Type = obj.Type; this.motherdish = obj.MotherDish; }
ActionOutput <List <MotherDishScheduleModel> > IMotherManager.GetMotherDishDailySchedule(int Id) { ActionOutput <List <MotherDishScheduleModel> > res = new ActionOutput <List <MotherDishScheduleModel> >(); try { var dishsch = (from p in Context.MotherDishDailySchedules join m in Context.MotherDishes on p.MotherDishId equals(m.Id) join mo in Context.MotherTbls on m.MotherId equals(mo.Id) where mo.UserId == Id && p.Date == DateTime.Now select p).ToList(); if (dishsch.Count <= 0) { var MotherDetails = Context.MotherTbls.Where(p => p.UserId == Id).FirstOrDefault(); if (MotherDetails != null) { var dishes = Context.MotherDishes.Where(p => p.MotherId == MotherDetails.Id).ToList(); List <MotherDishDailySchedule> list = new List <MotherDishDailySchedule>(); foreach (var item in dishes) { MotherDishDailySchedule mdds = new MotherDishDailySchedule(); mdds.Availabilty = true; mdds.Date = DateTime.Now; mdds.MotherDishId = item.DishId; mdds.Quantity = 15; mdds.Type = (int)AvailibiltyType.Both; list.Add(mdds); } if (list.Count != 0) { Context.MotherDishDailySchedules.AddRange(list); Context.SaveChanges(); } var listt = (from p in Context.MotherDishDailySchedules join m in Context.MotherDishes on p.MotherDishId equals(m.Id) join mo in Context.MotherTbls on m.MotherId equals(mo.Id) where mo.UserId == Id && p.Date == DateTime.Now select p).ToList(); res.Object = listt.Select(p => new MotherDishScheduleModel(p)).ToList(); res.Status = ActionStatus.Successfull; res.Message = "Mother's Daily Dish Scheduled fetched Successfully."; } else { res.Status = ActionStatus.Error; res.Message = "Mother doesn't exists"; } } else { res.Object = dishsch.Select(p => new MotherDishScheduleModel(p)).ToList(); res.Status = ActionStatus.Successfull; res.Message = "Mother's Daily Dish Scheduled fetched Successfully."; } } catch (Exception ex) { res.Status = ActionStatus.Error; res.Message = "Some Error Occurred"; } return(res); }