Example #1
0
 public HttpResponseMessage DeleteTranslationEstimations(CommonModelHelper_Transcription translationEstimationModel)
 {
     try
     {
         if (this.ModelState.IsValid)
         {
             var result = _service.DeleteTranscriptionEstimation(translationEstimationModel);
             if (result)
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, result));
             }
             else
             {
                 string message = "Not deleted successfully";
                 return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, message));
             }
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
     }
 }
Example #2
0
 public HttpResponseMessage Save(CommonModelHelper_Transcription model)
 {
     try
     {
         var estimationList = _service.SaveTranscriptionEstimation(model);
         if (estimationList)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, estimationList));
         }
         else
         {
             string message = "Error Saving Data";
             return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, message));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
        public bool DeleteTranscriptionEstimation(CommonModelHelper_Transcription model)
        {
            bool flag = false;

            try
            {
                var estimation = _dbContext.Estimations.Find(model.Estimation.ID);
                if (estimation != null)
                {
                    estimation.IsDeleted = true;
                    _dbContext.Entry(estimation).State = EntityState.Modified;
                    _dbContext.SaveChanges();
                    flag = true;
                }
            }
            catch (Exception ex)
            {
                IErrorLogService errorLog = new ErrorLogService();
                string           message  = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message;
                errorLog.SetErrorLog(model.CurrentUserID, "Estimation", message);
                throw new Exception(message);
            }
            return(flag);
        }
        public bool SaveTranscriptionEstimation(CommonModelHelper_Transcription model)
        {
            var isSuccessful = true;

            try
            {
                var culturalItems = new List <string> {
                    "BillingAddress", "ClientAddress", "BillingCompanyName", "DeliveryCompanyName", "DeliveryAddress", "Remarks", "CoordinatorNotes", "QuotationNotes"
                };
                ModelBinder.SetCulturalValue(model.Estimation, model, culturalItems);

                model.Estimation.EstimationNo   = GenerateEstimationNumber(model.ApplicationID);
                model.Estimation.EstimationType = (int)EstimationType.Transcription;
                if (model.Estimation.EstimationStatus == 0)
                {
                    model.Estimation.EstimationStatus = (int)EstimationStatus.Ordered;
                }
                ModelBinder.ModifyGuidValue(model.Estimation);
                //cmd.Parameters.AddWithValue("@ProjectID", DBNull.Value);
                if (model.Estimation.ID == Guid.Empty)
                {
                    model.Estimation.ID = Guid.NewGuid();
                    model.Estimation.RegistrationDate = DateTime.Now;
                    _dbContext.Estimations.Add(model.Estimation);
                }
                else
                {
                    //model.Estimation.FirstDeliveryDate = null;
                    //model.Estimation.FinalDeliveryDate = null;
                    _dbContext.Entry(model.Estimation).State = EntityState.Modified;
                }
                //Save or update Estimation details
                foreach (var item in model.EstimationDetails)
                {
                    item.EstimationID = model.Estimation.ID;
                    ModelBinder.ModifyGuidValue(item);

                    if ((item.ID == Guid.Empty) && (!item.IsMarkedForDelete))
                    {
                        item.ID = Guid.NewGuid();
                        var mapItem = Mapper.Map <EstimationDetailsModel, EstimationDetail>(item);
                        _dbContext.EstimationDetails.Add(mapItem);
                    }
                    else
                    {
                        if ((!item.IsMarkedForDelete) && (item.ID != Guid.Empty))
                        {
                            var mapItem = Mapper.Map <EstimationDetailsModel, EstimationDetail>(item);
                            _dbContext.Entry(mapItem).State = EntityState.Modified;
                        }
                        if ((item.IsMarkedForDelete) && (item.ID != Guid.Empty))
                        {
                            var itm = _dbContext.EstimationDetails.Find(item.ID);
                            _dbContext.EstimationDetails.Remove(itm);
                        }
                    }
                }
                #region "Commented"
                ////Save file type
                //var existingFileTypes = _dbContext.EstimationDeliveryFileTypes.Where(x => x.Estimation.ID == model.Estimation.ID).ToList();
                //var existingWorkContent = _dbContext.EstimationWorkContents.Where(x => x.Estimation.ID == model.Estimation.ID).ToList();
                //existingFileTypes?.ForEach(eft =>
                //{
                //    _dbContext.EstimationDeliveryFileTypes.Remove(eft);
                //});
                //existingWorkContent?.ForEach(ewc =>
                //{
                //    _dbContext.EstimationWorkContents.Remove(ewc);
                //});
                //model.FileTypes?.ForEach(ft =>
                //{
                //    var fileType = new EstimationDeliveryFileType
                //    {
                //        ID = Guid.NewGuid(),
                //        Estimation = model.Estimation,
                //        FileType = ft.FileType,
                //        Version = ft.Version,
                //        IsDeleted = false
                //    };
                //    _dbContext.EstimationDeliveryFileTypes.Add(fileType);
                //});
                ////Save work content
                //model.WorkContents?.ForEach(wc =>
                //{
                //    var content = new EstimationWorkContent
                //    {
                //        ID = Guid.NewGuid(),
                //        Estimation = model.Estimation,
                //        WorkContent = wc.WorkContent,
                //        IsDeleted = false
                //    };
                //    _dbContext.EstimationWorkContents.Add(content);
                //});
                #endregion "Commented"
                _dbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                isSuccessful = false;
                IErrorLogService errorLog = new ErrorLogService();
                string           message  = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message;
                errorLog.SetErrorLog(model.CurrentUserID, "TranscriptionEstimation", message);
                throw new Exception(message);
            }
            return(isSuccessful);
        }