public ActionResult GetAllServiceProvidersWithAvailableServices(ServiceTypeModel serviceType)
 {
     if (ModelState.IsValid)
     {
         var result = _serviceProviderService.GetAllProvidersWithAvailableServices(serviceType);
         return Json(new { success = true, data = result}, JsonRequestBehavior.AllowGet);
     }
     else
         return Json(new { success = false }, JsonRequestBehavior.AllowGet);
 }
        public ActionResult Edit(ServiceTypeModel model)
        {
            if (ModelState.IsValid)
            {
                var response = _serviceTypeService.Update(model);

                return Json(new { success = response.IsSucceed, message = response.Message }, JsonRequestBehavior.AllowGet);
            }

            return Json(new { success = false, errors = GetModelErrors() }, JsonRequestBehavior.AllowGet);
        }
 public ServiceTypeModel GetById(int id)
 {
     ServiceTypeModel serviceTypeModel = null;
     using (var unitOfWork = _unitOfWorkFactory.Create())
     {
         try
         {
             var entity = unitOfWork.ServiceTypeRepository.GetByID(id);
             if (entity != null)
             {
                 serviceTypeModel = new ServiceTypeModel(entity);
             }
             unitOfWork.Save();
         }
         catch (Exception e)
         {
             _logger.LogToFile(_logger.CreateErrorMessage(e));
         }
     }
     return serviceTypeModel;
 }
        private void DeleteServicePhases(ServiceTypeModel serviceType, IUnitOfWork unitOfWork)
        {
            var oldIds = serviceType.Phases.Select(y => y.Id);
            var actualIds = unitOfWork.ServicePhaseRepository.Get(x => x.ServiceTypeId == serviceType.Id).Select(x=>x.Id);
            var idsToDelete = actualIds.Where(x => !oldIds.Contains(x));
            var phasesToDelete =
                unitOfWork.ServicePhaseRepository.Get(x => idsToDelete.Contains(x.Id));

            foreach (var phase in phasesToDelete)
            {
                unitOfWork.ServicePhaseRepository.Delete(phase);
            }
        }
 public ResponseBase Update(ServiceTypeModel serviceType)
 {
     ResponseBase response;
     using (var unitOfWork = _unitOfWorkFactory.Create())
     {
         try
         {
             if (serviceType != null)
             {
                 unitOfWork.ServiceTypeRepository.Update(serviceType.ToEntity());
                 UpdateServicePhases(serviceType.Phases.Where(x => x.ServiceTypeId != 0).ToList(), unitOfWork);
                 AddServicePhases(serviceType.Phases.Where(x=>x.ServiceTypeId==0).ToList(),unitOfWork,serviceType.Id);
                 DeleteServicePhases(serviceType,unitOfWork);
             }
             unitOfWork.Save();
             response = new ResponseBase() { IsSucceed = true, Message = Modules.Resources.Logic.ServiceTypeModifySuccess };
         }
         catch (Exception e)
         {
             _logger.LogToFile(_logger.CreateErrorMessage(e));
             response = new ResponseBase() { IsSucceed = false, Message = Modules.Resources.Logic.ServiceTypeModifyFailed };
         }
     }
     return response;
 }
 public ResponseBase Insert(ServiceTypeModel serviceType)
 {
     ResponseBase response;
     using (var unitOfWork = _unitOfWorkFactory.Create())
     {
         try
         {
             if (serviceType != null)
             {
                 unitOfWork.ServiceTypeRepository.Insert(serviceType.ToEntity());
             }
             unitOfWork.Save();
             response = new ResponseBase() { IsSucceed = true, Message = Modules.Resources.Logic.ServiceTypeSaveSuccess };
         }
         catch (Exception e)
         {
             _logger.LogToFile(_logger.CreateErrorMessage(e));
             response = new ResponseBase() { IsSucceed = false, Message = Modules.Resources.Logic.ServiceTypeSaveFailed };
         }
         return response;
     }
 }