public void Create(Photo photo)
        {
            try
            {
                var mapPhoto = AutoMapper.Mapper.Map
                    <Data.Entities.Photo>(photo);

                _photoRepository.Add(mapPhoto);

                _unitOfWork.Commit();
            }
            catch (Exception exception)
            {
                throw new FaultException(exception.Message);
            }
        }
        public void Update(Photo photo)
        {
            try
            {
                var mapPhoto = AutoMapper.Mapper.Map
                    <Data.Entities.Photo>(photo);

                var actualPhoto = _photoRepository
                    .FindBy(p => p.Id == mapPhoto.Id)
                    .First();

                actualPhoto.NewsId = mapPhoto.NewsId;
                actualPhoto.File = mapPhoto.File;
                actualPhoto.Name = mapPhoto.Name;

                _unitOfWork.Commit();
            }
            catch (Exception exception)
            {
                throw new FaultException(exception.Message);
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(Person person)
        {
            if (ModelState.IsValid)
            {
                person.Id = Guid.NewGuid();

                if (Session["files"] == null)
                {
                    Session["files"] = new List<UploadFileInfo>();
                }

                var filesStorage = Session["files"] as List<UploadFileInfo>;

                if (filesStorage != null)
                {
                    foreach (UploadFileInfo file in filesStorage)
                    {
                        var photo = new Photo {Id = Guid.NewGuid()};
                        person.Photos.Add(photo);
                        photo.FileName = file.ContentType;
                        photo.CaptureDate = DateTime.Now;

                        using (var fs = new FileStream(file.FileName, FileMode.Open))
                        {
                            photo.Data = new byte[fs.Length];
                            fs.Read(photo.Data, 0, (int) fs.Length);
                        }
                    }
                    filesStorage.Clear();
                }
                db.People.Add(person);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.EmployerId = new SelectList(db.Employers, "Id", "Name", person.EmployerId);
            ViewBag.OccupationId = new SelectList(db.Occupations, "Id", "Name", person.OccupationId);
            return View(person);
        }