Exemplo n.º 1
0
        public ImageContract GetMyImages(string username)
        {
            var path = System.Web.Hosting.HostingEnvironment.MapPath("Images");

            path = HostingEnvironment.MapPath("~/Images/");
            if (path == null)
            {
                var uriPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\Images\\";
                path = new Uri(uriPath).LocalPath;
            }

            var userImages = unitOfWork.ImageRepository.Get()
                             .Where(i => i.Owner.UserName == username).ToList();
            var images = new ImageContract();

            images.ImageNames = userImages.Select(i => i.Name).ToList();
            images.ImagesPath = path;

            Mapper.CreateMap <ImageContract, Image>();
            Mapper.CreateMap <Domain.Image, ImageContract>();
            Mapper.CreateMap <ImageDataContract, Domain.Image>();
            Mapper.CreateMap <Image, ImageDataContract>();
            Mapper.CreateMap <UserContract, User>();
            Mapper.CreateMap <User, UserContract>();
            //images.Owner = Mapper.Map<UserContract>(userImages.FirstOrDefault()?.Owner);

            return(images);
        }
 public ActionResult SaveImageContract(ImageContract imageContract)
 {
     try
     {
         ContractService.SaveImageContract(imageContract);
         return(Json(true));
     }
     catch (Exception e) {
         return(Json(false, JsonRequestBehavior.AllowGet));
     }
 }
        public static ImageContract ConvertToImageContract(Image image)
        {
            if (image == null)
            {
                return(null);
            }

            ImageContract contractImage = new ImageContract()
            {
                ImageID = image.ImageID, GUID = image.GUID, Name = image.Name, FileData = image.FileData, ProfileID = image.ProfileID,
            };

            return(contractImage);
        }
        public static Image ConvertToImageEntity(ImageContract image)
        {
            if (image == null)
            {
                return(null);
            }
            Image entityImage = new Image()
            {
                ImageID   = image.ImageID,
                GUID      = image.GUID,
                Name      = image.Name,
                FileData  = image.FileData,
                ProfileID = image.ProfileID,
            };

            return(entityImage);
        }
Exemplo n.º 5
0
        public void SaveImageContract(ImageContract imageContract)
        {
            var contract = GetContractById(imageContract.IdContract);

            var image = new ImageContract();

            image.Name       = imageContract.Name;
            image.Base       = imageContract.Base;
            image.IdContract = contract.Id;

            if (contract.Images == null)
            {
                contract.Images = new List <ImageContract>();
            }

            contract.LastUpdate = DateTime.Now;
            contract.Images.Add(image);
            UnitOfWork.GetRepository <Contracts>().Update(contract);
            UnitOfWork.SaveChanges();
        }