public JsonResult AddService(Service service)
 {
     try
     {
         _portfolioService.AddService(service);
         //update service
         _portfolioService.UpdateService(service);
         if (service.Images != null)
         {
             //update images
             foreach (Image img in service.Images)
             {
                 img.Service_Id = service.Id;
                 _imageService.Update(img);
             }
         }
         if (service.Videos != null)
         {
             //update videos
             foreach (Video video in service.Videos)
             {
                 video.Service_Id = service.Id;
                 _videoService.Update(video);
             }
         }
     }
     catch
     {
         return Json(false);
     }
     return Json(true);
 }
 public JsonResult RemoveService(Service service)
 {
     try
     {
         _portfolioService.RemoveService(service.Id);
     }
     catch
     {
         return Json(false);
     }
     return Json(true);
 }
 public JsonResult GetServiceById(int id)
 {
     var service = _portfolioService.GetServiceById(id);
     Service serviceReturn = new Service();
     if (service != null)
     {
         serviceReturn.Id = service.Id;
         serviceReturn.SectionId = service.SectionId;
         serviceReturn.ServiceName = service.ServiceName;
         serviceReturn.ServiceDetail = service.ServiceDetail;
     }
     return Json(serviceReturn, JsonRequestBehavior.AllowGet);
 }
        public JsonResult EditService(Service service)
        {
            try
            {
                if (service.Images != null)
                {
                    //update images
                    foreach (Image img in service.Images)
                    {
                        img.Service_Id = service.Id;
                        _imageService.AddOrUpdate(img);
                    }
                }
                if (service.Videos != null)
                {
                    //update videos
                    foreach (Video video in service.Videos)
                    {
                        video.Service_Id = service.Id;
                        _videoService.Update(video);
                    }
                }
                //update service
                _portfolioService.UpdateService(service);

            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            return Json(true);
        }
 public void AddService(Service service)
 {
     _serviceRepository.Add(service);
 }
 public void UpdateService(Service service)
 {
     _serviceRepository.AddOrUpdate(service);
 }