Ejemplo n.º 1
0
        public async Task <IEnumerable <MotherModel> > MapToMotherModel(IEnumerable <Mother> mothersList)
        {
            IList <MotherModel> returnedList = new List <MotherModel>();

            foreach (var mother in mothersList)
            {
                MotherModel retMother = await MapToMotherModel(mother);

                returnedList.Add(retMother);
            }
            return(returnedList);
        }
Ejemplo n.º 2
0
        public HttpResponseMessage UpdateMotherProfile(MotherModel model)
        {
            var result = _motherManager.UpdateMotherProfile(model);

            if (result.Status == ActionStatus.Successfull)
            {
                return(new JsonContent(result.Message, Status.Success, new { user = result.Object }).ConvertToHttpResponseOK());
            }
            else
            {
                return(new JsonContent(result.Message, Status.Failed, result).ConvertToHttpResponseOK());
            }
        }
Ejemplo n.º 3
0
        ActionOutput <MotherModel> IMotherManager.GetMotherProfile(int Id)
        {
            ActionOutput <MotherModel> res = new ActionOutput <MotherModel>();
            MotherModel resModel           = new MotherModel();

            try
            {
                var existss = Context.UserTbls.Where(p => p.Id == Id).FirstOrDefault();
                if (existss != null)
                {
                    resModel.user = existss;
                    var exists = Context.MotherTbls.Where(p => p.UserId == existss.Id).FirstOrDefault();
                    if (exists != null)
                    {
                        resModel.mother = exists;
                        var dishes = Context.MotherDishes.Where(p => p.MotherId == exists.Id).ToList();


                        resModel.dish = dishes;
                        res.Status    = ActionStatus.Successfull;
                        res.Message   = "Mother Details fetched 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);
        }
Ejemplo n.º 4
0
        public async Task <MotherModel> MapToMotherModel(Mother mother)
        {
            MotherModel retMother = null;

            try
            {
                retMother               = _mapper.Map <MotherModel>(mother);
                retMother.FullName      = mother.Name.FullName();
                retMother.FullAddress   = mother.Address.FullAddress();
                retMother.OrphansCount  = -1;
                retMother.HusbandsNames = "";
                foreach (var fam in mother.Families)
                {
                    if (fam.Father == null || fam.Father.Name == null)
                    {
                        fam.Father = await _ApiClient.Fathers_GetAsync(fam.FatherId);
                    }
                    if (mother.Families.Count > 1)
                    {
                        retMother.HusbandsNames += fam.Father.Name.FullName() + ", ";
                    }
                    else
                    {
                        retMother.HusbandsNames += fam.Father.Name.FullName() + ", ";
                    }
                }
                if (retMother.HusbandsNames.EndsWith(", "))
                {
                    retMother.HusbandsNames = retMother.HusbandsNames.Substring(0, retMother.HusbandsNames.Length - 2);
                }
            }
            catch
            {
                retMother = null;
            }
            return(retMother);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        ActionOutput <List <MotherModel> > IHomeManager.GetMothersList(double Longitute, double Latitute, DateTime ReqDate, int CategoryId, int AvailabiltyTypes)
        {
            ActionOutput <List <MotherModel> > res = new ActionOutput <List <MotherModel> >();

            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 <MotherModel> model = new List <MotherModel>();

                foreach (var item in _fmothers)
                {
                    MotherModel mm = new MotherModel();
                    mm.user   = item.UserTbl;
                    mm.mother = item;
                    mm.dish   = DailyDishSchedule.Where(p => p.MotherDish.MotherId == item.Id && p.Availabilty == true).Select(p => p.MotherDish).ToList();
                    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);
        }