Beispiel #1
0
        public async Task <ActionResult <VendorPictureForGetDTO> > Delete(int id)
        {
            if (!await _vendorPictureRepository.IsExist(id).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("VendorPicture", id))));
            }

            VendorPicture vendorPicture = await _vendorPictureRepository.GetAsync(id).ConfigureAwait(true);

            _vendorPictureRepository.Remove(vendorPicture);
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            FileOperations.DeleteFile($"Vendors/{vendorPicture.VendorId}/Pictures", vendorPicture.PictureName);

            VendorPictureForGetDTO vendorPictureDto = _mapper.Map <VendorPictureForGetDTO>(vendorPicture);

            return(Ok(vendorPictureDto));
        }
Beispiel #2
0
        public async Task <ActionResult <IReadOnlyList <VendorPictureForGetDTO> > > Post([FromForm] VendorPictureForAddDTO model)
        {
            if (!await _vendorRepository.IsExist(model.VendorId).ConfigureAwait(true))
            {
                return(NotFound(new ApiResponse(404, StringConcatenates.NotExist("Vendor", model.VendorId))));
            }

            foreach (var file in model.Pictures)
            {
                FileOperations.WriteFile($"Vendors/{model.VendorId}/Pictures", file);

                VendorPicture vendorPicture = new VendorPicture
                {
                    VendorId    = model.VendorId,
                    PictureName = file.FileName
                };
                await _vendorPictureRepository.AddAsync(vendorPicture).ConfigureAwait(true);
            }
            await _unitOfWork.CompleteAsync().ConfigureAwait(true);

            List <VendorPictureForGetDTO> vendorPictures = _mapper.Map <List <VendorPictureForGetDTO> >(await _vendorPictureRepository.GetByVendorAsync(model.VendorId).ConfigureAwait(true));

            return(Ok(vendorPictures));
        }
        public ActionResult AddProfilePic(int vendorId, int albumTypeId, HttpPostedFileBase AddPicture)
        {
            try
            {
                if (Session["userCode"] != null)
                {
                    bool result = vl.CheckVendorIdnAlbumTypeIdInVendorAlbum(vendorId, albumTypeId);

                    Vendor        vendor = (from c in entity.Vendors where c.VendorId == vendorId select c).FirstOrDefault();
                    VendorPicture tp     = new VendorPicture();
                    if (result == true)
                    {
                        var albumId = (from c in entity.VendorAlbums where c.VendorId == vendorId && c.AlbumTypeId == albumTypeId select c.VendorAlbumId).Single();
                        int AlbumId = Convert.ToInt32(albumId);
                        if (AddPicture != null)
                        {
                            tp.VendorPictureData = new byte[AddPicture.ContentLength];
                            AddPicture.InputStream.Read(tp.VendorPictureData, 0, AddPicture.ContentLength);
                        }
                        else
                        {
                            Session["message"] = "no picture has been selected";
                            return(RedirectToAction("UserPanel", "Home"));
                        }
                        tp.VendorId                 = vendorId;
                        tp.VendorAlbumId            = AlbumId;
                        tp.AlbumTypeId              = albumTypeId;
                        tp.VendorPictureAdminPermit = true;
                        tp.CountryId                = vendor.CountryId;
                        tp.CityId = vendor.CityId;

                        tp.VendorPicturePrivacy     = true;
                        tp.VendorPictureDateOfAdded = DateTime.Now;
                        entity.VendorPictures.Add(tp);

                        if (entity.SaveChanges() > 0)
                        {
                            var pictureId = (from c in entity.VendorPictures
                                             where c.VendorId == vendorId && c.AlbumTypeId == albumTypeId
                                             orderby c.VendorPictureId descending
                                             select c.VendorPictureId).First();
                            vendor.VendorProfilePicId = Convert.ToInt32(pictureId);
                            entity.SaveChanges();

                            var            d        = (from c in entity.Vendors where c.VendorId == vendorId select c).FirstOrDefault();
                            Nullable <int> ProPicId = d.VendorProfilePicId;
                            if (ProPicId != null)
                            {
                                byte[] pic = (from c in entity.VendorPictures where c.VendorId == vendorId && c.AlbumTypeId == 1 orderby c.VendorPictureId descending select c.VendorPictureData).First();
                                if (pic != null)
                                {
                                    Session["pp"] = pic;
                                }
                            }
                            Session["message"] = "Profile Picture added";
                            return(RedirectToAction("UserPanel", "Home"));
                        }
                        else
                        {
                            Session["message"] = "not added";
                            return(RedirectToAction("UserPanel", "Home"));
                        }
                    }
                    else
                    {
                        if (AddPicture != null)
                        {
                            tp.VendorPictureData = new byte[AddPicture.ContentLength];
                            AddPicture.InputStream.Read(tp.VendorPictureData, 0, AddPicture.ContentLength);
                        }
                        else
                        {
                            Session["message"] = "no picture has been selected";
                            return(RedirectToAction("UserPanel", "Home"));
                        }

                        VendorAlbum ta = new VendorAlbum();
                        ta.VendorAlbumName = "Profile Picture";
                        ta.VendorId        = vendorId;
                        ta.AlbumTypeId     = albumTypeId;
                        ta.CityId          = vendor.CityId;
                        ta.CountryId       = vendor.CountryId;

                        ta.VendorAlbumAdminPermit   = true;
                        ta.VendorAlbumPrivacy       = true;
                        ta.VendorDateOfAlbumCreated = DateTime.Now;
                        entity.VendorAlbums.Add(ta);
                        entity.SaveChanges();
                        tp.VendorId = vendorId;
                        var albumId = (from c in entity.VendorAlbums where c.VendorId == vendorId && c.AlbumTypeId == albumTypeId select c.VendorAlbumId).Single();
                        int AlbumId = Convert.ToInt32(albumId);
                        tp.VendorAlbumId            = AlbumId;
                        tp.AlbumTypeId              = albumTypeId;
                        tp.VendorPictureAdminPermit = true;
                        tp.CountryId = vendor.CountryId;
                        tp.CityId    = vendor.CityId;

                        tp.VendorPicturePrivacy     = true;
                        tp.VendorPictureDateOfAdded = DateTime.Now;
                        entity.VendorPictures.Add(tp);
                        if (entity.SaveChanges() > 0)
                        {
                            int pictureId = (from c in entity.VendorPictures
                                             where c.VendorId == vendorId && c.AlbumTypeId == albumTypeId
                                             orderby c.VendorPictureId descending
                                             select c.VendorPictureId).First();
                            vendor.VendorProfilePicId = pictureId;
                            entity.SaveChanges();

                            var            d        = (from c in entity.Vendors where c.VendorId == vendorId select c).FirstOrDefault();
                            Nullable <int> ProPicId = d.VendorProfilePicId;
                            if (ProPicId != null)
                            {
                                byte[] pic = (from c in entity.VendorPictures where c.VendorId == vendorId && c.AlbumTypeId == 1 orderby c.VendorPictureId descending select c.VendorPictureData).First();
                                if (pic != null)
                                {
                                    Session["pp"] = pic;
                                }
                            }

                            Session["message"] = "Profile Picture added";
                            return(RedirectToAction("UserPanel", "Home"));
                        }
                        else
                        {
                            Session["message"] = "not added";
                            return(RedirectToAction("UserPanel", "Home"));
                        }
                    }
                }
                else
                {
                    Session["message"] = "please log in to See the List";
                    return(RedirectToAction("Index", "Home"));
                }
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Vendor", "AddProfilePic")));
            }
        }
Beispiel #4
0
 public void Remove(VendorPicture vendorPicture)
 {
     _context.Remove(vendorPicture);
 }
Beispiel #5
0
 public VendorPicture Edit(VendorPicture vendorPicture)
 {
     _context.Entry(vendorPicture).State = EntityState.Modified;
     return(vendorPicture);
 }
Beispiel #6
0
        public async Task <VendorPicture> AddAsync(VendorPicture vendorPicture)
        {
            await _context.VendorsPictures.AddAsync(vendorPicture);

            return(vendorPicture);
        }