public IHttpActionResult Save(ServiceRequestModel Model)
        {
            ServiceRequest SR = new ServiceRequest();

            SR.Id = Model.Id;
            SR.InsuranceTypeId      = Model.InsuranceTypeId;
            SR.Code                 = Model.Code;
            SR.UserId               = Model.UserId;
            SR.TimeOccured          = DateTime.Now.ToUniversalTime();
            SR.ClaimType            = Model.ClaimType;
            SR.UsageType            = Model.UsageType;
            SR.RegistrationCategory = Model.RegistrationCategory;
            SR.VehicleNo            = Model.VehicleNo;
            SR.VehicleValue         = Model.VehicleValue;
            SR.VehicleYear          = Model.VehicleYear;
            SR.IsFinanced           = Model.IsFinanced;
            SR.Location             = Model.Location;
            SR.ClientType           = Model.ClientType;
            SR.FuelType             = Model.FuelType;
            //SR.Images = Model.Images;

            try
            {
                using (AppDBContext context = new AppDBContext())
                {
                    var repo = new ServiceRequestRepository(context);
                    if (SR.Id == 0)
                    {
                        SR.Id = repo.Add(SR);
                        AssignRequestToAgents(SR.Id);

                        //Added temporary
                        Utility.SendEmail("Request " + SR.Code + " Raised", SR.Code);
                    }
                    else
                    {
                        repo.Update(SR);
                    }

                    if (SR.Images != null)
                    {
                        var imageRepo = new VehicleImageRepository(context);
                        imageRepo.Update(SR.Id, SR.Images);
                    }
                }

                return(Json(SR));
            }
            catch (Exception ex)
            {
                Logger.Log(typeof(ServiceRequestController), ex.Message + ex.StackTrace, LogType.ERROR);
                return(InternalServerError());
            }
        }
        public void Edit(EducationSecurityPrincipal user, ServiceRequestModel viewModel)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }
            var updatedServiceRequest = ServiceRequestRepository.Items.Include(s => s.ServiceType).
                                        Include(s => s.FulfillmentDetails).
                                        Include(s => s.Student.ApprovedProviders).
                                        Include(s => s.Student.School.UserRoles).
                                        Include("Student.StudentAssignedOfferings.ServiceOffering.Provider").
                                        SingleOrDefault(s => s.Id == viewModel.Id);

            if (updatedServiceRequest == null)
            {
                throw new EntityNotFoundException("Cannot find specified service request.");
            }
            IPermission permission = PermissionFactory.Current.Create("EditRequest", updatedServiceRequest);

            permission.GrantAccess(user);
            var currentServiceRequestFulfillment = updatedServiceRequest.FulfillmentDetails.OrderByDescending(f => f.CreateTime).FirstOrDefault();
            int currentStatusId   = currentServiceRequestFulfillment.FulfillmentStatusId;
            int?currentOfferingId = currentServiceRequestFulfillment.FulfilledById;

            viewModel.CopyTo(updatedServiceRequest);
            if (currentStatusId != viewModel.SelectedStatusId)
            {
                CreateFulfillmentDetail(updatedServiceRequest, user, viewModel);
            }
            else if (currentOfferingId != viewModel.SelectedAssignedOfferingId)
            {
                UpdateCurrentFulfillmentDetail(updatedServiceRequest, viewModel);
            }
            updatedServiceRequest.LastModifyingUser = user.Identity.User;
            updatedServiceRequest.LastModifyTime    = DateTime.Now;
            ServiceRequestRepository.Update(updatedServiceRequest);
            RepositoryContainer.Save();
        }
 public object Update(tbRequest request)
 {
     return(serviceRequestRepository.Update(request));
 }