public MotherScheduleModel(MotherDailySchedule obj) { this.Id = obj.Id; this.MotherId = obj.MotherId; this.CreatedDate = obj.Date; this.Type = obj.Type; this.Availabilty = obj.Availabilty; this.FirstName = obj.MotherTbl.UserTbl.FirstName; this.LastName = obj.MotherTbl.UserTbl.LastName; this.Email = obj.MotherTbl.UserTbl.Email; this.Phone = obj.MotherTbl.UserTbl.Phone; this.UserId = obj.MotherTbl.UserId; }
ActionOutput IMotherManager.UpdateMotherDailySchedule(MotherScheduleModel model) { ActionOutput res = new ActionOutput(); try { var sch = (from p in Context.MotherDailySchedules join m in Context.MotherTbls on p.MotherId equals(m.Id) where m.UserId == model.UserId && p.Date == DateTime.Now select p).FirstOrDefault(); if (sch == null) { var MotherDetails = Context.MotherTbls.Where(p => p.UserId == model.UserId).FirstOrDefault(); if (MotherDetails != null) { MotherDailySchedule mds = new MotherDailySchedule(); mds.Availabilty = model.Availabilty;; mds.Date = model.CreatedDate; mds.Type = model.Type; mds.MotherId = MotherDetails.Id; Context.MotherDailySchedules.Add(mds); Context.SaveChanges(); res.Status = ActionStatus.Successfull; res.Message = "Daily Schedule Saved Successfully."; } else { res.Status = ActionStatus.Error; res.Message = "Mother doesn't exists"; } } else { sch.Availabilty = model.Availabilty;; sch.Date = model.CreatedDate; sch.Type = model.Type; res.Status = ActionStatus.Successfull; res.Message = "Daily Schedule Saved Successfully."; } } catch (Exception ex) { res.Status = ActionStatus.Error; res.Message = "Some Error Occurred"; } return(res); }
ActionOutput <MotherScheduleModel> IMotherManager.GetMotherDailySchedule(int Id) { ActionOutput <MotherScheduleModel> res = new ActionOutput <MotherScheduleModel>(); try { var sch = (from p in Context.MotherDailySchedules join m in Context.MotherTbls on p.MotherId equals(m.Id) where m.UserId == Id && p.Date == DateTime.Now select p).FirstOrDefault(); if (sch == null) { var MotherDetails = Context.MotherTbls.Where(p => p.UserId == Id).FirstOrDefault(); if (MotherDetails != null) { MotherDailySchedule mds = new MotherDailySchedule(); mds.Availabilty = true; mds.Date = DateTime.Now; mds.Type = (int)AvailibiltyType.Both; mds.MotherId = MotherDetails.Id; Context.MotherDailySchedules.Add(mds); Context.SaveChanges(); 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); } Context.MotherDishDailySchedules.AddRange(list); Context.SaveChanges(); res.Object = new MotherScheduleModel(mds); res.Status = ActionStatus.Successfull; res.Message = "Daily Schedule Fetched Successfully."; } else { res.Status = ActionStatus.Error; res.Message = "Mother doesn't exists"; } } else { var dishsch = (from p in Context.MotherDishDailySchedules join m in Context.MotherDishes on p.MotherDishId equals(m.Id) where m.MotherId == sch.MotherId && p.Date == DateTime.Now select p).ToList(); if (dishsch.Count <= 0) { var dishes = Context.MotherDishes.Where(p => p.MotherId == sch.MotherId).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); } Context.MotherDishDailySchedules.AddRange(list); Context.SaveChanges(); } res.Object = new MotherScheduleModel(sch); res.Status = ActionStatus.Successfull; res.Message = "Daily Schedule Fetched Successfully."; } } catch (Exception ex) { res.Status = ActionStatus.Error; res.Message = "Some Error Occurred"; } return(res); }