public ServiceCategoryModel SaveCategoryService(ServiceCategoryModel model)
 {
     //unitOfWork.StartTransaction();
     ServiceCatagoryRepository repo = new ServiceCatagoryRepository(unitOfWork);
     ServiceCategory serviceCategory = new ServiceCategory();
     AutoMapper.Mapper.Map(model, serviceCategory);
     repo.Insert(serviceCategory);
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(serviceCategory, model);
     return model;
 }
 public ServiceCategoryModel GetCategoryServiceById(int categoryServiceId)
 {
     //unitOfWork.StartTransaction();
     ServiceCatagoryRepository repo = new ServiceCatagoryRepository(unitOfWork);
     ServiceCategoryModel serviceCategoryModel = new ServiceCategoryModel();
     ServiceCategory serviceCategory = new ServiceCategory();
     AutoMapper.Mapper.Map(serviceCategoryModel, serviceCategory);
     serviceCategory = repo.GetAll().Where(x => x.ServiceCategoryId == categoryServiceId).FirstOrDefault();
     //unitOfWork.Commit();
     AutoMapper.Mapper.Map(serviceCategory, serviceCategoryModel);
     return serviceCategoryModel;
 }
        public async Task<IHttpActionResult> PutServiceCategory(int id)
        {
            try {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                ServiceCategory modal = new ServiceCategory();
                var root = HttpContext.Current.Server.MapPath(Utility.Constants.BASE_FILE_UPLOAD_PATH);
                Directory.CreateDirectory(root);
                var provider = new MultipartFormDataStreamProvider(root);
                var resultModel = await Request.Content.ReadAsMultipartAsync(provider);
                if (resultModel.FormData["model"] == null)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    modal = JsonConvert.DeserializeObject<ServiceCategory>(resultModel.FormData["model"]);
                    //modal.Description = resultModel.FormData["Description"];
                }
                if (resultModel.FileData.Count > 0)
                {
                    string fileName;

                    if (HttpContext.Current.Request.Files != null)
                    {
                        for (var i = 0; i < resultModel.FileData.Count; i++)
                        {
                            var file = HttpContext.Current.Request.Files[i];
                            fileName = file.FileName;
                            file.SaveAs(Path.Combine(root, Utility.Constants.SERVICES_LOGO, fileName));
                            modal.CategoryPicturePath = fileName;
                        }
                    }
                }

                ServiceCategoryModel serviceModel = new ServiceCategoryModel();
                AutoMapper.Mapper.Map(modal, serviceModel);
                if (id == modal.ServiceCategoryId)
                {
                    serviceModel = serviceCategoryService.UpadteCategoryService(serviceModel);
                    return Ok(serviceModel);
                }
                return BadRequest();
            }
            catch(Exception ex)
            {
                return BadRequest(ex.Message);
            }
        }