public SaleListing CreateSaleListingObject(SaleListing newsalelisting, Account owner, ProductType product)
        {
            SaleListing salelisting = newsalelisting;

            salelisting.ExpirationDate = DateTime.Now.AddDays(DAYSBEFOREEXPIRING);
            salelisting.Owner          = owner.Company;
            salelisting.ProductType    = product;
            salelisting.Subscription   = new Subscription(); //might handled otherwise.
            salelisting.Comments       = new List <Comment>();
            return(salelisting);
        }
Beispiel #2
0
 public bool UpdateSaleListing(SaleListingDTO viewmodel)
 {
     try
     {
         SaleListing updated = Mapper.Map <SaleListingDTO, SaleListing>(viewmodel);
         SaleListing current = _saleListingRepository.GetSaleListing(viewmodel.ID);
         current = _createAndUpdateService.UpdateSaleListingFields(current, updated);
         _saleListingRepository.UpdateSaleListing(current);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #3
0
 public bool AddOrUpdateSubscription(eSubscription sub, SaleListingDTO salelistingviewmodel)
 {
     try
     {
         SaleListing  salelisting  = _saleListingRepository.GetSaleListing(salelistingviewmodel.ID);
         Subscription subscription = _subscriptionService.CreateSubscription(sub);
         _saleListingRepository.UpdateSaleListingSubscription(salelisting, subscription);
         //_log.LogSaleListing(salelisting.Owner.ID, salelisting.ID, eLogSaleListingType.Update);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #4
0
        public List <CommentDTO> GetCommentsForSaleListing(int salelistingID)
        {
            try
            {
                SaleListing       salelisting = _saleListingRepository.GetSaleListing(salelistingID);
                var               comments    = salelisting.Comments;
                List <CommentDTO> viewmodels  = comments.Select(e => Mapper.Map <Comment, CommentDTO>(e)).ToList();

                return(viewmodels);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #5
0
 public bool AddComment(int salelistingid, CommentDTO commentviewmodel)
 {
     try
     {
         SaleListing salelisting = _saleListingRepository.GetSaleListing(salelistingid);
         Comment     comment     = Mapper.Map <CommentDTO, Comment>(commentviewmodel);
         SaleListingComment(comment);
         salelisting.Comments.Add(comment);
         _saleListingRepository.UpdateSaleListing(salelisting);
         //_log.LogSaleListing(salelisting.Owner.ID, salelisting.ID, eLogSaleListingType.Comment);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #6
0
        public bool AddAnswerForComment(int salelistingID, int commentID, CommentDTO answerviewmodel)
        {
            try
            {
                SaleListing salelisting = _saleListingRepository.GetSaleListing(salelistingID);
                Comment     comment     = salelisting.Comments.Single(e => e.ID == commentID);

                CommentAnswer answer = Mapper.Map <CommentDTO, CommentAnswer>(answerviewmodel);

                comment.Answers.Add(answer);
                _saleListingRepository.UpdateSaleListing(salelisting);
                //_log.LogSaleListing(salelisting.Owner.ID, salelisting.ID, eLogSaleListingType.Comment);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #7
0
        public bool RemoveComment(SaleListingDTO saleviewmodel, int id)
        {
            try
            {
                SaleListing salelisting = _saleListingRepository.GetSaleListing(saleviewmodel.ID);

                var comment = salelisting.Comments.FirstOrDefault(e => e.ID == id);
                if (comment != null)
                {
                    salelisting.Comments.Remove(comment);
                    _saleListingRepository.UpdateSaleListing(salelisting);
                    //_log.LogSaleListing(salelisting.Owner.ID, salelisting.ID, eLogSaleListingType.Comment);
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #8
0
 public bool RemoveImageSaleListing(int salelistingid, int imageid)
 {
     try
     {
         SaleListing salelisting = _saleListingRepository.GetSaleListing(salelistingid);
         var         image       = salelisting.Images.FirstOrDefault(e => e.ID == imageid);
         if (image != null)
         {
             salelisting.Images.Remove(image);
             _imageService.RemoveImageFromFolder(image.ImageURL);
             _saleListingRepository.UpdateSaleListing(salelisting);
             //_log.LogSaleListing(salelisting.Owner.ID, salelisting.ID, eLogSaleListingType.Update);
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
        /// <summary>
        /// Updates the fields for a SaleListing object, before it is calling the database.
        /// The reason is, that the viewmodel does not map reference property, like CreatedBy or Comments proberly.
        /// </summary>
        /// <returns></returns>
        public SaleListing UpdateSaleListingFields(SaleListing current, SaleListing updated)
        {
            SaleListing copy = new SaleListing
            {
                ID             = current.ID,
                CreatedBy      = current.CreatedBy,
                Comments       = current.Comments,
                Images         = current.Images, //Does not update images from this!
                Description    = updated.Description,
                ExpirationDate = current.ExpirationDate,
                Price          = updated.Price,
                Title          = updated.Title,
                Owner          = current.Owner,
                Subscription   = current.Subscription,
                ProductType    = updated.ProductType,
                Color          = updated.Color,
                CPU            = updated.CPU,
                Depth          = updated.Depth,
                FuelType       = updated.FuelType,
                Harddisk       = updated.Harddisk,
                Height         = updated.Height,
                Kilometers     = updated.Kilometers,
                KmPrLiter      = updated.KmPrLiter,
                LastService    = updated.LastService,
                Manufacturer   = updated.Manufacturer,
                Length         = updated.Length,
                Model          = updated.Model,
                NoOfDoors      = updated.NoOfDoors,
                RAM            = updated.RAM,
                ScreenSize     = updated.ScreenSize,
                Thickness      = updated.Thickness,
                VatPayed       = updated.VatPayed,
                Weight         = updated.Weight,
                Width          = updated.Width,
                Year           = updated.Year
            };

            return(copy);
        }
Beispiel #10
0
 public bool AddImageSaleListing(SaleListingDTO viewmodel, ImageUploadDTO img)
 {
     try
     {
         if (_imageService.ValidateExtension(img.FileName))
         {
             string imgurl = _imageService.SaveImageToFolder(img);
             Image  image  = new Image {
                 ImageURL = imgurl, Type = img.ImageType
             };
             SaleListing salelisting = _saleListingRepository.GetSaleListing(viewmodel.ID);
             salelisting.Images.Add(image);
             _saleListingRepository.UpdateSaleListing(salelisting);
             //_log.LogSaleListing(salelisting.Owner.ID, salelisting.ID, eLogSaleListingType.Update);
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }