Beispiel #1
0
        public IResponseDTO GetByCustomerId(Guid?id)
        {
            try
            {
                // List<CityWorkShop> cityWorkShops = new List<CityWorkShop>();
                var         WorkShopPrefer = _WorkShopPreferRepositroy.Get(x => x.CustomerId == id && x.Prefer == true);
                List <Guid> WorkShopIds    = null;
                WorkShopIds = WorkShopPrefer.Select(c => (Guid)c.WorkShopId).ToList();
                var Wrokshop = _WorkshopRepositroy.Get(w => WorkShopIds.Contains((Guid)w.WorkshopId)).ToList();



                var WorkshopsList = Wrokshop.Select(x => new
                {
                    Address      = x.Address,
                    CreationDate = x.CreationDate,
                    WorkshopId   = x.WorkshopId,
                    Name         = x.Name,
                    IsTrust      = x.IsTrust,
                    ImageUrl     = x.ImageUrl,
                    Token        = x.Token,
                    CityId       = x.CityId,
                    CityName     = x.City == null ? "" : x.City.CityName,
                    Prefer       = x.Prefer,

                    MapLatitude  = x.MapLatitude,
                    MapLangitude = x.MapLangitude,
                    Email        = x.Email,
                    Password     = "",
                    Phone        = x.Phone,
                    Info         = x.Info,
                    OwnerName    = x.OwnerName,
                    OwnerImage   = x.OwnerImage,
                    IsAvailable  = x.IsAvailable,
                    HasSparePart = x.HasSparePart,
                    HasWarranty  = x.HasWarranty,
                    RateCount    = x.WorkshopRate.Count,
                    RateAVG      = x.WorkshopRate.Count > 0 ? x.WorkshopRate.Average(y => y.Rate) : 0.0m,
                }).ToList();
                _response.Data     = WorkshopsList;
                _response.IsPassed = true;
                _response.Message  = "Done";
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + string.Format("{0} - {1} ", ex.Message, ex.InnerException != null ? ex.InnerException.FullMessage() : "");
            }
            return(_response);
        }
Beispiel #2
0
        public IResponseDTO GetCustomerByWorkShopId(Guid id)
        {
            try
            {//GetCustomerByWorkShopId
                var Chats = _ChatRepositroy.Filter(x => x.WorkShopId == id).ToList();


                List <ResponseChat> Wrokshops = new List <ResponseChat>();
                foreach (var customerChat in Chats)
                {
                    if (customerChat.CustomerId != null)
                    {
                        var customerHasChat = _CustomerRepositroy.Find(customerChat.CustomerId);
                        var chat            = new ResponseChat();
                        chat.Content      = customerChat.Content;
                        chat.CreationDate = customerChat.CreationDate;
                        chat.CountUnRead  = _ChatRepositroy.Get(x => x.WorkShopId == id && x.IsRead == false).Count();
                        chat.CustomerName = customerHasChat.Name;
                        chat.ImageUrl     = customerHasChat.ImageUrl;
                        chat.CustomerId   = customerHasChat.CustomerId;

                        Wrokshops.Add(chat);
                    }
                }

                var result = Wrokshops.GroupBy(x => x.CustomerId)
                             .Select(x => x.OrderByDescending(y => y.CreationDate).First());

                _response.Data = result.Select(x => new
                {
                    Content      = x.Content,
                    CountUnRead  = x.CountUnRead,
                    CreationDate = x.CreationDate,
                    CustomerName = x.CustomerName,
                    CustomerId   = x.CustomerId,
                    ImageUrl     = x.ImageUrl,
                });
                _response.IsPassed = true;
                _response.Message  = "Done";
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + string.Format("{0} - {1} ", ex.Message, ex.InnerException != null ? ex.InnerException.FullMessage() : "");
            }
            return(_response);
        }
Beispiel #3
0
        public IResponseDTO GetAllWorkshopCity()
        {
            try
            {
                List <CityWorkShop> cityWorkShops = new List <CityWorkShop>();
                var         Workshops             = _WorkshopRepositroy.Get(x => x.CityId != null);
                List <Guid> CityIds = null;
                CityIds = Workshops.Select(c => (Guid)c.CityId).ToList();
                var WrokshopCity = _CityWorkshopRepositroy.Get(w => CityIds.Contains((Guid)w.CityId)).ToList();
                foreach (var Model in WrokshopCity)
                {
                    var count = Workshops.Count(x => x.CityId == Model.CityId);
                    var city  = new CityWorkShop();
                    city.CityName     = Model.CityName;
                    city.CityId       = Model.CityId;
                    city.WorshopCount = count;
                    cityWorkShops.Add(city);
                }

                _response.Data     = cityWorkShops;
                _response.IsPassed = true;
                _response.Message  = "Done";
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + string.Format("{0} - {1} ", ex.Message, ex.InnerException != null ? ex.InnerException.FullMessage() : "");
            }
            return(_response);
        }
Beispiel #4
0
        public IResponseDTO GetByCustomerId(Guid?id)
        {
            try
            {
                var WorkshopRates = _WorkshopRateRepositroy.Get(x => x.CustomerId == id);


                var WorkshopRatesList = _mapper.Map <WorkshopRateVM>(WorkshopRates);
                _response.Data     = WorkshopRatesList;
                _response.IsPassed = true;
                _response.Message  = "Done";
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + string.Format("{0} - {1} ", ex.Message, ex.InnerException != null ? ex.InnerException.FullMessage() : "");
            }
            return(_response);
        }
        public IResponseDTO EditAdvertisement(AdvertisementIncloudVM model)
        {
            try
            {
                var _AdvertisementCategory = model.AdvertisementCategory?.ToList();
                var _AdvertisementCity     = model.AdvertisementCity?.ToList();
                model.AdvertisementCategory = null;
                model.AdvertisementCity     = null;
                var DbAdvertisement = _mapper.Map <Advertisement>(model);
                var entityEntry     = _AdvertisementRepositroy.Update(DbAdvertisement);
                var _ACategory      = _AdvertisementCategoryRepositroy.Get(x => x.AdsId == model.AdsId).ToList();
                if (_ACategory != null && _ACategory.Count > 0)
                {
                    _AdvertisementCategoryRepositroy.RemoveRange(_ACategory);
                }
                if (_AdvertisementCategory != null && _AdvertisementCategory.Count > 0)
                {
                    _AdvertisementCategory.ForEach(x => x.AdsId = model.AdsId);
                    _AdvertisementCategoryRepositroy.AddRange(_mapper.Map <List <AdvertisementCategory> >(_AdvertisementCategory));
                }
                var _ACity = _AdvertisementCityRepositroy.Get(x => x.AdsId == model.AdsId).ToList();
                if (_ACity != null && _ACity.Count > 0)
                {
                    _AdvertisementCityRepositroy.RemoveRange(_ACity);
                }
                if (_AdvertisementCity != null && _AdvertisementCity.Count > 0)
                {
                    _AdvertisementCity.ForEach(x => x.AdsId = model.AdsId);
                    _AdvertisementCityRepositroy.AddRange(_mapper.Map <List <AdvertisementCity> >(_AdvertisementCity));
                }
                int save = _unitOfWork.Commit();

                if (save == 200)
                {
                    _response.Data     = model;
                    _response.IsPassed = true;
                    _response.Message  = "Ok";
                }
                else
                {
                    _response.Data     = null;
                    _response.IsPassed = false;
                    _response.Message  = "Not saved";
                }
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + ex.Message;
            }

            return(_response);
        }
Beispiel #6
0
        public IResponseDTO GetByCustomerId(Guid?id)
        {
            try
            {
                var Orders = _OrderRepositroy.Get(x => x.CustomerId == id, includeProperties: "Workshop");


                var OrdersList = _mapper.Map <List <OrderVM> >(Orders);
                _response.Data     = OrdersList;
                _response.IsPassed = true;
                _response.Message  = "Done";
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + string.Format("{0} - {1} ", ex.Message, ex.InnerException != null ? ex.InnerException.FullMessage() : "");
            }
            return(_response);
        }
        public IResponseDTO PostMarket(MarketVM model)
        {
            try
            {
                var res = _MarketRepositroy.Get(x => x.MarketEmail == model.MarketEmail);
                if (res != null)
                {
                    _response.Data     = null;
                    _response.IsPassed = false;
                    _response.Message  = "This email already exists";
                }
                var DbMarket = _mapper.Map <Market>(model);

                var Market = _mapper.Map <MarketVM>(_MarketRepositroy.Add(DbMarket));

                int save = _unitOfWork.Commit();

                if (save == 200)
                {
                    _response.Data     = model;
                    _response.IsPassed = true;
                    _response.Message  = "Ok";
                }
                else
                {
                    _response.Data     = null;
                    _response.IsPassed = false;
                    _response.Message  = "Not saved";
                }
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + ex.Message;
            }
            return(_response);
        }
        public IResponseDTO UpdateNotificationsStatus(Guid WorkshopId)
        {
            try
            {
                var DbWorkshopNotifications = _WorkshopNotificationsRepositroy.Get(x => x.WorkshopId == WorkshopId).ToList();
                foreach (var Notification in DbWorkshopNotifications)
                {
                    Notification.IsRead = true;
                    _WorkshopNotificationsRepositroy.Update(Notification);
                    _unitOfWork.Commit();
                }


                int save = _unitOfWork.Commit();

                if (save == 200)
                {
                    _response.Data     = null;
                    _response.IsPassed = true;
                    _response.Message  = "Ok";
                }
                else
                {
                    _response.Data     = null;
                    _response.IsPassed = false;
                    _response.Message  = "Not saved";
                }
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + string.Format("{0} - {1} ", ex.Message, ex.InnerException != null ? ex.InnerException.FullMessage() : "");
            }

            return(_response);
        }
        public IResponseDTO GetAllCustomerNotifications()
        {
            try
            {
                var CustomerNotificationss = _CustomerNotificationsRepositroy.GetAll();


                var CustomerNotificationssList = _mapper.Map <List <CustomerNotificationsVM> >(CustomerNotificationss);
                var count = _CustomerNotificationsRepositroy.Get(x => x.IsRead == false).Count();
                if (CustomerNotificationssList == null || CustomerNotificationssList.Count == 0)
                {
                    _response.Data = new
                    {
                    };
                }

                else
                {
                    _response.Data = new
                    {
                        Notifications = CustomerNotificationssList,
                        countNew      = count
                    };
                }

                _response.IsPassed = true;
                _response.Message  = "Done";
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + string.Format("{0} - {1} ", ex.Message, ex.InnerException != null ? ex.InnerException.FullMessage() : "");
            }
            return(_response);
        }
Beispiel #10
0
 // Saudi id : '1E5DE704-5A80-4CAA-AB98-910AC31E205D'
 public IResponseDTO GetSaudiCity()
 {
     try
     {
         var Citys = _CityRepositroy.Get(x => x.CountryId == Guid.Parse("1E5DE704-5A80-4CAA-AB98-910AC31E205D"))
                     .OrderBy(y => y.Order).OrderBy(z => z.CityName);
         var CitysList = _mapper.Map <List <CityVM> >(Citys);
         _response.Data     = CitysList;
         _response.IsPassed = true;
         _response.Message  = "Done";
     }
     catch (Exception ex)
     {
         _response.Data     = null;
         _response.IsPassed = false;
         _response.Message  = "Error " + string.Format("{0} - {1} ", ex.Message, ex.InnerException != null ? ex.InnerException.FullMessage() : "");
     }
     return(_response);
 }
 public IResponseDTO GetAdvertisementByCategory(int page, Guid categoryId, Guid cityId, Guid CustomerId)
 {
     try
     {
         var paging = new DTO.Pageing();
         paging.pageNumber = page;
         var Advertisements = _AdvertisementRepositroy.Get(x => x.Available == true,
                                                           includeProperties: "Market,AdvertisementCity,AdvertisementCategory")
                              .Skip(paging.skip).Take(paging.pageSize);
         var AdvertisementsList = new List <AdvertisementVM2>();
         foreach (var add in Advertisements)
         {
             var Category = add.AdvertisementCategory.FirstOrDefault(x => x.CategoryId == categoryId);
             if (Category == null)
             {
                 continue;
             }
             var City = add.AdvertisementCity.FirstOrDefault(x => x.CityId == cityId);
             if (City == null)
             {
                 continue;
             }
             _AdvertisementViewRepositroy.Add(new AdvertisementView()
             {
                 AdsViewId  = Guid.NewGuid(),
                 AdsId      = add.AdsId,
                 CustomerId = CustomerId,
             });
             AdvertisementsList.Add(_mapper.Map <AdvertisementVM2>(add));
         }
         _unitOfWork.Commit();
         //var AdvertisementsList = _mapper.Map<List<AdvertisementVM2>>(Advertisements);
         _response.Data     = AdvertisementsList;
         _response.IsPassed = true;
         _response.Message  = "Done";
     }
     catch (Exception ex)
     {
         _response.Data     = null;
         _response.IsPassed = false;
         _response.Message  = "Error " + ex.Message;
     }
     return(_response);
 }
 // Saudi id : 'fd3f74d2-f3ca-4f17-b3be-cdf6ef800f7a'
 public IResponseDTO GetSaudiCity()
 {
     try
     {
         var Citys = _CityRepositroy.Get(x => x.CountryId == Guid.Parse("fd3f74d2-f3ca-4f17-b3be-cdf6ef800f7a"))
                     .OrderBy(y => y.Order).OrderBy(z => z.CityName).ToList();
         //Citys.ForEach(x => x.CityId = Guid.Parse("695314ee-5a98-40de-a8d2-50b0130c5a0c"));
         var CitysList = _mapper.Map <List <CityVM> >(Citys);
         _response.Data     = CitysList;
         _response.IsPassed = true;
         _response.Message  = "Done";
     }
     catch (Exception ex)
     {
         _response.Data     = null;
         _response.IsPassed = false;
         _response.Message  = "Error " + ex.Message;
     }
     return(_response);
 }
Beispiel #13
0
        public IResponseDTO WaitingUpdate(Guid?id)
        {
            try
            {
                var Advertisements = _AdvertisementUpdateRepositroy.Get(x => x.AdsId == id).FirstOrDefault();


                var AdvertisementsList = _mapper.Map <AdvertisementUpdateVM>(Advertisements);
                _response.Data     = AdvertisementsList;
                _response.IsPassed = true;
                _response.Message  = "Done";
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + ex.Message;
            }
            return(_response);
        }
Beispiel #14
0
 public IResponseDTO GetCategorysAds(Guid CustomerId)
 {
     try
     {
         var Categorys = _CategoryRepositroy.Get(includeProperties: "AdvertisementCategory").ToList();
         var ads       = _AdvertisementRepositroy.Get(x => x.Special == true && x.Available == true, includeProperties: "Market");
         List <CategoryVM> CategorysList = new List <CategoryVM>();// _mapper.Map<List<CategoryVM>>(Categorys);
         foreach (var c in Categorys)
         {
             if (c.AdvertisementCategory != null && c.AdvertisementCategory.Count > 0)
             {
                 CategorysList.Add(_mapper.Map <CategoryVM>(c));
             }
         }
         var adsList = _mapper.Map <List <AdvertisementVM2> >(ads);
         foreach (var add in ads)
         {
             _AdvertisementViewRepositroy.Add(new AdvertisementView()
             {
                 AdsViewId  = Guid.NewGuid(),
                 AdsId      = add.AdsId,
                 CustomerId = CustomerId,
             });
         }
         _unitOfWork.Commit();
         _response.Data = new DTO.AdsCategryDTO()
         {
             category = CategorysList,
             ads      = adsList,
         };
         _response.IsPassed = true;
         _response.Message  = "Done";
     }
     catch (Exception ex)
     {
         _response.Data     = null;
         _response.IsPassed = false;
         _response.Message  = "Error " + ex.Message;
     }
     return(_response);
 }
Beispiel #15
0
        public IResponseDTO UpdateStatus(Guid WorkshopId)
        {
            try
            {
                var DbWorkshop = _WorkshopRepositroy.Get(x => x.WorkshopId == WorkshopId).FirstOrDefault();
                if (DbWorkshop.IsAvailable != null)
                {
                    DbWorkshop.IsAvailable = !DbWorkshop.IsAvailable;
                }
                else
                {
                    DbWorkshop.IsAvailable = true;
                }
                var entityEntry = _WorkshopRepositroy.Update(DbWorkshop);


                int save = _unitOfWork.Commit();

                if (save == 200)
                {
                    _response.Data     = null;
                    _response.IsPassed = true;
                    _response.Message  = "Ok";
                }
                else
                {
                    _response.Data     = null;
                    _response.IsPassed = false;
                    _response.Message  = "Not saved";
                }
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + string.Format("{0} - {1} ", ex.Message, ex.InnerException != null ? ex.InnerException.FullMessage() : "");
            }

            return(_response);
        }