public Entity.BaseResponse <Entity.Crop> Manage([FromForm] Entity.CropModel request)
 {
     Entity.BaseResponse <Entity.Crop> response = new Entity.BaseResponse <Entity.Crop>(true);
     try
     {
         var status = _service.Manage(request);
         response.IsSuccess = status.Success;
         response.Message   = status.Message;
         response.Data      = status.Data;
     }
     catch (Exception ex)
     {
         return(new Entity.BaseResponse <Entity.Crop>(false, ex.Message));
     }
     return(response);
 }
 public Entity.ActionStatus Manage(Entity.CropModel crop)
 {
     try
     {
         Entity.Crop         cropEntity   = Mapper.Configuration.Mapper.Map <Entity.CropModel, Entity.Crop>(crop);
         var                 dbCrop       = Mapper.Configuration.Mapper.Map <Entity.Crop, Model.Crop>(cropEntity);
         Entity.ActionStatus actionStatus = null;
         if (crop.Guid == null || crop.Guid == Guid.Empty)
         {
             dbCrop.Guid = Guid.NewGuid();
             if (crop.ImageFile != null)
             {
                 // upload image
                 dbCrop.Image = SaveCropImage(dbCrop.Guid, crop.ImageFile);
             }
             dbCrop.CompanyGuid = component.helper.SolutionConfiguration.CompanyId;
             dbCrop.CreatedDate = DateTime.Now;
             dbCrop.CreatedBy   = component.helper.SolutionConfiguration.CurrentUserId;
             actionStatus       = _cropRepository.Insert(dbCrop);
             actionStatus.Data  = Mapper.Configuration.Mapper.Map <Model.Crop, Entity.Crop>(actionStatus.Data);
         }
         else
         {
             var uniqGreenhouse = _cropRepository.GetByUniqueId(x => x.Guid == dbCrop.Guid);
             if (uniqGreenhouse == null)
             {
                 throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Crop");
             }
             if (crop.ImageFile != null)
             {
                 if (File.Exists(component.helper.SolutionConfiguration.UploadBasePath + uniqGreenhouse.Image) && crop.ImageFile.Length > 0)
                 {
                     //if already exists image then delete  old image from server
                     File.Delete(component.helper.SolutionConfiguration.UploadBasePath + uniqGreenhouse.Image);
                 }
                 if (crop.ImageFile.Length > 0)
                 {
                     // upload new image
                     dbCrop.Image = SaveCropImage(dbCrop.Guid, crop.ImageFile);
                 }
             }
             else
             {
                 dbCrop.Image = uniqGreenhouse.Image;
             }
             dbCrop.CreatedDate = uniqGreenhouse.CreatedDate;
             dbCrop.CreatedBy   = uniqGreenhouse.CreatedBy;
             dbCrop.UpdatedDate = DateTime.Now;
             dbCrop.UpdatedBy   = component.helper.SolutionConfiguration.CurrentUserId;
             dbCrop.CompanyGuid = component.helper.SolutionConfiguration.CompanyId;
             actionStatus       = _cropRepository.Update(dbCrop);
             actionStatus.Data  = Mapper.Configuration.Mapper.Map <Model.Crop, Entity.Crop>(actionStatus.Data);
         }
         return(actionStatus);
     }
     catch (Exception ex)
     {
         _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
         return(new Entity.ActionStatus
         {
             Success = false,
             Message = ex.Message
         });
     }
 }