Exemplo n.º 1
0
        public void SuggestPrice(int watchId, int userId, decimal suggestedPrice)
        {
            Models.Watch watch = watchRepository.Get().Where(w => w.Id == watchId).Include(w => w.SuggestedPrices).FirstOrDefault();

            if (watch == null)
            {
                throw new NotFoundException("ساعت");
            }
            if (!watch.SuggestPrice)
            {
                throw new NotAllowedException("پیشنهاد قیمت");
            }

            SuggestPrice suggestPrice = new SuggestPrice
            {
                User_Id         = userId,
                Watch_Id        = watchId,
                Suggested_Price = suggestedPrice
            };

            suggestPriceRepository.Insert(suggestPrice);

            watch.SuggestedPrices.Add(suggestPrice);

            watchRepository.Update(watch);

            unitOfWork.Commit();
        }
Exemplo n.º 2
0
 public IResponse GetWatchDetail(int watchId)
 {
     try
     {
         Models.Watch watch = watchBusiness.GetWatchDetail(watchId);
         return(new Response <Models.Watch>
         {
             Result = new PagedResult <Models.Watch>
             {
                 Count = 1,
                 Data = new List <Models.Watch>
                 {
                     watch,
                 }
             }
         });
     }
     catch (Exception e)
     {
         return(new Response <Models.Watch>
         {
             Success = false,
             Message = e.Message,
         });
     }
 }
Exemplo n.º 3
0
        public void InsertWatch(Models.Watch watch, byte[] mainImage, List <byte[]> images)
        {
            watch.MainImagePath = Utility.Image.Save(mainImage);

            foreach (byte[] img in images)
            {
                watch.Images.Add(new Image
                {
                    Path = Utility.Image.Save(mainImage)
                });
            }

            watchRepository.Insert(watch);
            unitOfWork.Commit();
        }
Exemplo n.º 4
0
 public IResponse UpdateWatch(Models.Watch watch)
 {
     try
     {
         watchBusiness.UpdateWatch(watch);
         return(new Response <Models.Watch>());
     }
     catch (Exception e)
     {
         return(new Response <Models.Watch>()
         {
             Success = false, Message = e.Message, Result = null
         });
     }
 }
Exemplo n.º 5
0
        public async Task <IResponse> InsertWatch(Models.Watch watch)
        {
            try
            {
                User user = await userManager.FindByNameAsync(User.Identity.Name);

                watch.User_Id = user.Id;
                watchBusiness.InsertWatch(watch, watch.MainImage, watch.SubImages);
                return(new Response <Models.Watch>());
            }
            catch (Exception e)
            {
                return(new Response <Models.Watch>()
                {
                    Success = false, Message = e.Message, Result = null
                });
            }
        }
Exemplo n.º 6
0
        public Models.Watch GetWatchDetail(int watchId)
        {
            Models.Watch result = watchRepository.Get().Where(w => w.Id == watchId).Include(w => w.WatchBookmarks)
                                  .Include(w => w.Brand)
                                  .Include(w => w.Images)
                                  .Include(w => w.OwnerUser)
                                  .FirstOrDefault();

            if (result == null)
            {
                throw new NotFoundException("ساعت");
            }

            //Prevent self looping
            result.Brand.Watches     = null;
            result.OwnerUser.Watches = null;

            return(result);
        }
Exemplo n.º 7
0
 public void UpdateWatch(Models.Watch watch)
 {
     watchRepository.Update(watch);
     unitOfWork.Commit();
 }