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 IUserManager.AddDishForMother(AddDishForMotherModel model) { var GetMotherID = Context.MotherTbls.Where(a => a.UserId == model.MotherID).FirstOrDefault().Id; var ExistingDish = Context.MotherDishes.Where(a => a.MotherId == GetMotherID && a.DishId == model.DishId && a.IsDeleted == false ).FirstOrDefault(); if (ExistingDish != null) { return(new ActionOutput { Status = ActionStatus.Error, Message = "Dish Already Exists." }); } string FileName = ""; if (model.DishImage != null) { FileName = UtilitiesHelp.SavePostedFile(AppFolderName.DishImage, model.DishImage); } var MotherDish = new MotherDish { MotherId = GetMotherID, DishId = model.DishId, Image = FileName, Limit = 100, Price = 200, CreatedOn = DateTime.Now, IsDeleted = false, IsMainDish = false, IsSignatureDish = false }; Context.MotherDishes.Add(MotherDish); Context.SaveChanges(); // return new ActionOutput // { // Status = ActionStatus.Error, // Message = "This Part already exists." // }; return(new ActionOutput { Status = ActionStatus.Successfull, Message = "Dish Added Successfully." }); }
public MotherDishModel(MotherDish obj) { this.Id = obj.Id; this.MotherId = obj.MotherId; this.DishId = obj.DishId; this.DishName = obj.Dish.Name; this.Limit = obj.Limit; this.Price = obj.Price; this.Image = UtilitiesHelp.GetFilePath(AppFolderName.DishImage, obj.Image); this.CreatedOn = obj.CreatedOn.ToString(AppDefaults.DateTimeFormat); this.IsDeleted = obj.IsDeleted; this.IsMainDish = obj.IsMainDish; this.IsSignatureDish = obj.IsSignatureDish; }
ActionOutput <MotherListingModel> IMotherManager.UpdateMotherProfile(MotherModel model) { ActionOutput <MotherListingModel> res = new ActionOutput <MotherListingModel>(); MotherListingModel resModel = new MotherListingModel(); try { var existss = Context.UserTbls.Where(p => p.Id == model.user.Id).FirstOrDefault(); if (existss != null) { existss.LastName = model.user.LastName; existss.Latitute = model.user.Latitute; existss.Longitute = model.user.Longitute; existss.Province = model.user.Province; existss.Address = model.user.Address; existss.City = model.user.City; existss.Email = model.user.Email; existss.FirstName = model.user.FirstName; resModel.user = new UserModel(existss); var exists = Context.MotherTbls.Where(p => p.Id == model.mother.Id).FirstOrDefault(); if (exists != null) { exists.Commision = model.mother.Commision; exists.CoverPhoto = model.mother.CoverPhoto; exists.DDeliveryTime = model.mother.DDeliveryTime; exists.Description = model.mother.Description; exists.DOfflineTime = model.mother.DOfflineTime; exists.LDeliveryTime = model.mother.LDeliveryTime; exists.LOfflineTime = model.mother.LOfflineTime; exists.ProfilePhoto = model.mother.ProfilePhoto; exists.Ratings = (model.mother.Ratings != null) ? model.mother.Ratings : 0; resModel.mother = new MotherListModel(exists); var dishes = Context.MotherDishes.Where(p => p.MotherId == exists.Id).ToList(); if (dishes != null) { var dellist = new List <MotherDish>(); foreach (var item in dishes) { int counter = 0; foreach (var mitem in model.dish) { if (mitem.DishId == item.DishId) { counter = 1; dellist.Add(mitem); } } if (counter == 0) { item.IsDeleted = true; } } foreach (var itemsss in dellist) { model.dish.Remove(itemsss); } Context.SaveChanges(); List <MotherDish> _list = new List <MotherDish>(); foreach (var item in model.dish) { MotherDish m = new MotherDish(); m.DishId = item.DishId; m.MotherId = exists.Id; m.Image = item.Image; m.Limit = item.Limit; m.IsDeleted = false; m.IsSignatureDish = item.IsSignatureDish; m.CreatedOn = DateTime.Now; _list.Add(m); } Context.MotherDishes.AddRange(_list); Context.SaveChanges(); } else { List <MotherDish> _list = new List <MotherDish>(); foreach (var item in model.dish) { MotherDish m = new MotherDish(); m.DishId = item.DishId; m.MotherId = exists.Id; m.Image = item.Image; m.Limit = item.Limit; m.IsDeleted = false; m.IsMainDish = true; m.IsSignatureDish = item.IsSignatureDish; m.CreatedOn = DateTime.Now; _list.Add(m); } Context.MotherDishes.AddRange(_list); Context.SaveChanges(); } resModel.dish = model.dish.Select(p => new MotherDishModel(p)).ToList(); res.Status = ActionStatus.Successfull; res.Message = "Mother Details updated successfully."; res.Object = resModel; } else { res.Status = ActionStatus.Error; res.Message = "Mother doesnt exists"; } } else { res.Status = ActionStatus.Error; res.Message = "Mother doesn't exists"; } } catch (Exception ex) { res.Status = ActionStatus.Error; res.Message = "Some Error Occurred"; } return(res); }
ActionOutput <List <MotherDish> > IHomeManager.GetAmazingDishesList(double Longitute, double Latitute, DateTime ReqDate, int CategoryId, int AvailabiltyTypes) { ActionOutput <List <MotherDish> > res = new ActionOutput <List <MotherDish> >(); try { var datas = (from m in Context.MotherTbls join u in Context.UserTbls on m.UserId equals(u.Id) where (u.Status == (int)UserStatuss.Approved || u.Status == (int)UserStatuss.Subscribed)select new { m, u }).ToList(); var data = new List <MotherTbl>(); foreach (var item in datas) { if (UtilitiesHelp.HaversineDistance(new LatLng(Convert.ToDouble(item.u.Latitute), Convert.ToDouble(item.u.Longitute)), new LatLng(Latitute, Longitute)) <= 5) { data.Add(item.m); } } var DaySchedule = Context.MotherDailySchedules.Where(p => p.Date == ReqDate).AsQueryable(); if (AvailabiltyTypes == (int)AvailibiltyType.Dinner) { DaySchedule = DaySchedule.Where(p => p.Type == (int)AvailibiltyType.Both && p.Type == (int)AvailibiltyType.Dinner).AsQueryable(); } else { DaySchedule = DaySchedule.Where(p => p.Type == (int)AvailibiltyType.Both && p.Type == (int)AvailibiltyType.Lunch).AsQueryable(); } List <MotherTbl> _mothers = new List <MotherTbl>(); foreach (var item in data) { var s = DaySchedule.Where(p => p.MotherId == item.Id).FirstOrDefault(); if (s != null) { if (s.Availabilty == true) { _mothers.Add(item); } } } var DailyDishSchedule = Context.MotherDishDailySchedules.Where(p => p.Date == DateTime.Now).AsQueryable(); List <MotherTbl> _fmothers = new List <MotherTbl>(); foreach (var item in _mothers) { var s = DailyDishSchedule.Where(p => p.MotherDish.MotherId == item.Id).ToList(); if (s.Count != 0) { foreach (var items in s) { if (items.Availabilty == true) { if (!_fmothers.Contains(item)) { if (CategoryId != 0) { if (items.MotherDish.Dish.CategoryId == CategoryId) { _fmothers.Add(item); } } else { _fmothers.Add(item); } } } } } } List <MotherDish> model = new List <MotherDish>(); foreach (var item in _fmothers) { MotherDish mm = new MotherDish(); mm = DailyDishSchedule.Where(p => p.MotherDish.MotherId == item.Id && p.Availabilty == true).Select(p => p.MotherDish).OrderBy(p => p.Id).FirstOrDefault(); model.Add(mm); } res.Object = model; res.Message = "Data Fetched Successfully"; res.Status = ActionStatus.Successfull; } catch (Exception ex) { res.Status = ActionStatus.Error; res.Message = "Some Error Occurred"; } return(res); }