private Task <PrintResponseModel> PrintEstimate(EstimationModel estimation, string printType, string printMessasge) { return(Task.Run(() => { try { var print = printBusiness(printType).Print(estimation); if (print != null) { return new PrintResponseModel { Print = print, Status = EstimationApplicationConstant.OkStatus, Message = printMessasge }; } } catch (NotImplementedException ex) { logger.LogError(ex.Message); return new PrintResponseModel { Status = EstimationApplicationConstant.PrintWarningStatus, Message = printMessasge }; } return null; })); }
public HttpResponseMessage DeleteTranslationEstimations(EstimationModel translationEstimationModel) { try { if (this.ModelState.IsValid) { var result = _service.DeleteTaskQuotation(translationEstimationModel); if (result != null) { 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)); } }
public EstimationModel ApprovePendingRequest(EstimationModel model) { var result = new EstimationModel(); try { var estimation = _dbContext.Estimations.Find(model.ID); var estimationApproval = _dbContext.EstimationApprovals.Find(model.ID); if (estimation.EstimationStatus != (int)EstimationStatus.Approved) { //Update Estimation estimation.EstimationStatus = (int)EstimationStatus.Approved; _dbContext.Entry(estimation).State = EntityState.Modified; //Update EstimationApproval estimationApproval.Status = (int)EstimationApprovalStatus.Approved; _dbContext.Entry(estimationApproval).State = EntityState.Modified; _dbContext.SaveChanges(); result.EstimationStatusName = Enum.GetName(typeof(EstimationStatus), estimation.EstimationStatus); result.PageButtonAttribute = new PageAttributes(result.EstimationStatusName); result.EstimationStatusID = estimation.EstimationStatus; } } catch (Exception ex) { IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "ApprovePendingRequest", message); throw new Exception(message); } return(result); }
/* Get actual identity value for our Estimation table using a SP */ private string GetNextRegistrationID(EstimationModel model) { SqlCommand cmd; long NextRegID; SqlParameter ReturnParameter; try { _sqlConnService.OpenConnection(); cmd = new SqlCommand("SP_RetrieveNextIdentity", _sqlConnService.CreateConnection()); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@TABLENAME", "Estimation"); ReturnParameter = cmd.Parameters.Add("@NEXT_IDENTITY_VALUE", SqlDbType.BigInt); ReturnParameter.Direction = ParameterDirection.ReturnValue; cmd.ExecuteNonQuery(); NextRegID = Convert.ToInt64(ReturnParameter.Value.ToString()); } catch (Exception ex) { NextRegID = 0; } finally { _sqlConnService.CloseConnection(); } return(NextRegID.ToString()); }
public List <EstimationModel> DeleteEstimation(EstimationModel model) { Estimation Estimation; List <Estimation> MasterDataList; try { MasterDataList = _dbContext.Estimations.ToList(); Estimation = MasterDataList.Find(item => item.ID == model.ID); if (Estimation != null) { //Estimation.IsDeleted = true; _dbContext.Entry(Estimation).State = EntityState.Modified; _dbContext.SaveChanges(); } } catch (Exception ex) { IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "Estimation", message); throw new Exception(message); } BaseModel.CurrentCulture = model.CurrentCulture; BaseModel.CurrentUserID = model.CurrentUserID; return(GetAllEstimationList(BaseModel)); }
public HttpResponseMessage Save(EstimationModel model) { try { //if (this.ModelState.IsValid) //{ var estimationList = _service.SaveEstimation(model); if (estimationList) { return(Request.CreateResponse(HttpStatusCode.OK, estimationList)); } else { string message = "Error Saving Data"; return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, message)); } //} //else //{ // return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); //} } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public HttpResponseMessage GenerateQuotationPdf(EstimationModel model) { try { var viewData = new System.Web.Mvc.ViewDataDictionary { { "Estimation", model } }; var html = RenderViewToString("TaskQuotation", "~/Views/Template/TaskQuotation.cshtml", viewData); var res = PdfSharpConvert(html); var result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new StreamContent(new MemoryStream(res)); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); result.Content.Headers.ContentLength = res.Length; result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileName = $"Estimate_{DateTime.Now.ToShortDateString()}.pdf"; return(result); //var buffer = HtmlToPdf(html, ""); //var result = Request.CreateResponse(HttpStatusCode.OK); //result.Content = new StreamContent(new MemoryStream(buffer)); //result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); //result.Content.Headers.ContentLength = buffer.Length; //result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); //result.Content.Headers.ContentDisposition.FileName = $"Estimate_{DateTime.Now.ToShortDateString()}.pdf"; //return result; } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
public override PrintModel Print(EstimationModel estimation) { var estimationDataText = GetEstimationDataText(estimation); var filePath = WriteToFile(estimationDataText); return(new PrintModel { Estimation = estimation, PrintMessageOutput = EstimationApplicationConstant.PrintFileMessage + filePath }); }
public EstimationModel EmailConfirmation(EstimationModel model) { var result = new EstimationModel(); try { var estimation = _dbContext.Estimations.Find(model.ID); var employee = _dbContext.Employees.Find(estimation.ApprovalID); var coordinator = _dbContext.Employees.Find(model.CoordinatorID ?? new Guid()); var emailService = new EmailService(); var emials = new List <KeyValuePair <string, Employee> >(); if (estimation.EstimationStatus != (int)EstimationStatus.Ordered) { //Update Estimation estimation.EstimationStatus = (int)EstimationStatus.Ordered; _dbContext.Entry(estimation).State = EntityState.Modified; //Send confirmation email var dictonary = new Dictionary <string, Employee>() { { employee.Email, employee }, { coordinator.Email, coordinator } }; emials.AddRange(dictonary); var subject = $"Quotation confirmation email for Estimation No : {estimation.EstimationNo}"; emials.ForEach(email => { if (!string.IsNullOrEmpty(email.Key)) { var sb = new StringBuilder(); var empName = email.Value.GetType().GetProperty($"Name_{model.CurrentCulture}").GetValue(email.Value, null)?.ToString(); sb.Append($"Dear {empName},"); sb.Append("<br/>"); sb.Append($"You approved the request for Estimation No: {estimation.EstimationNo}."); sb.Append($" <a href={model.PageUrl}>Click here</a> to go to the estimation page."); sb.Append("<br/><br/>"); sb.Append("Thank you<br/>HiWork Team"); emailService.SendEmail(email.Key, null, null, subject, sb.ToString(), null, true); } }); _dbContext.SaveChanges(); result.EstimationStatusName = Enum.GetName(typeof(EstimationStatus), estimation.EstimationStatus); result.PageButtonAttribute = new PageAttributes(result.EstimationStatusName); result.EstimationStatusID = estimation.EstimationStatus; } } catch (Exception ex) { IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "EmailConfirmation", message); throw new Exception(message); } return(result); }
public EstimationModel ApprovalRequest(EstimationModel model) { var result = new EstimationModel(); try { var estimation = _dbContext.Estimations.Find(model.ID); var employee = _dbContext.Employees.Find(estimation.ApprovalID); var emailService = new EmailService(); var sb = new StringBuilder(); if (estimation.EstimationStatus != (int)EstimationStatus.Waiting_for_approval) { //Update estimation estimation.EstimationStatus = (int)EstimationStatus.Waiting_for_approval; _dbContext.Entry(estimation).State = EntityState.Modified; //Add EstimationApproval var obj = new EstimationApproval { ID = Guid.NewGuid(), ApplicationID = model.ApplicationId, ApproverID = estimation.ApprovalID, EstimationID = estimation.ID, Estimation = estimation, OrderID = _dbContext.Orders.SingleOrDefault(e => e.Estimation.ID == estimation.ID)?.ID, Description = $"Estimation No: {estimation.EstimationNo} needs to approve.", Status = (int)EstimationApprovalStatus.Unread, CreatedBy = model.CurrentUserID, CreatedDate = DateTime.Now.ToUniversalTime() }; _dbContext.EstimationApprovals.Add(obj); } var subject = $"Quotation email for Estimation No : {estimation.EstimationNo}"; var empName = employee.GetType().GetProperty($"Name_{model.CurrentCulture}").GetValue(employee, null)?.ToString(); sb.Append($"Dear {empName},"); sb.Append("<br/>"); sb.Append($"You have an approval request for Estimation No: {estimation.EstimationNo}."); sb.Append($" <a href={model.PageUrl}>Click here</a> to go to the estimation page."); sb.Append("<br/><br/>"); sb.Append("Thank you<br/>HiWork Team"); emailService.SendEmail(employee.Email, null, null, subject, sb.ToString(), null, true); _dbContext.SaveChanges(); result.EstimationStatusName = Enum.GetName(typeof(EstimationStatus), estimation.EstimationStatus); result.PageButtonAttribute = new PageAttributes(result.EstimationStatusName); result.EstimationStatusID = estimation.EstimationStatus; } catch (Exception ex) { result = null; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "ApprovalRequest", message); throw new Exception(message); } return(result); }
private string GenerateEstimationNumber(EstimationModel model) { string NextRegistrationID; string AppCode; IApplicationService appService = new ApplicationService(new ApplicationRepository(new UnitOfWork())); NextRegistrationID = GetNextRegistrationID(model); AppCode = appService.GetApplicationCode(model.ApplicationId); return(Helper.GenerateUniqueID(AppCode, NextRegistrationID)); }
public IActionResult CalculatePrice([FromBody] EstimationModel estimationParam) { if (estimationParam == null) { return(NotFound(new { message = "Parameter can not be null" })); } var price = _estimationService.CalculatePrice(estimationParam); return(Ok(price)); }
public HttpResponseMessage EmailConfirmation(EstimationModel model) { try { var result = _service.EmailConfirmation(model); return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
public HttpResponseMessage OrderLoss(EstimationModel model) { try { var result = _service.OrderEstimationOrderLoss(model.ID); return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
private string GetNextRegistrationID(EstimationModel model) { var items = (from a in _dbContext.Estimations select a.RegistrationID).ToList(); if (items != null && items.Count > 0) { return((items.Max() + 1).ToString()); } else { return("1"); } //Estimation LastEstimation; //LastEstimation = _dbContext.Estimations.Where(es => es.ApplicationID == model.ApplicationId).LastOrDefault(); //return (LastEstimation.RegistrationID + 1).ToString(); }
public IActionResult Estimate(Guid id, [FromBody] EstimationModel estimationModel) { lock (gameLock) { var game = gameRepository.Get(id).Result; var player = User.Identity.Name; var estimation = new Estimation(estimationModel.Value, player); if (game.Estimate(estimation) is Failure <string> f) { return(StatusCode((int)HttpStatusCode.Forbidden, f.Data)); } gameRepository.Update(game).Wait(); return(Ok()); } }
public void CalculatePrice_PriceCalculation_ShouldReturnActualPrice() { // Arrange var service = this.CreateService(); EstimationModel estimationModel = new EstimationModel { DiscountPercentage = 5, PricePerGram = 5500, Weight = 2 }; // Act var svcResult = service.CalculatePrice( estimationModel); // Assert Assert.True(Convert.ToDecimal(svcResult.Result).Equals((decimal)10450.00)); this.mockRepository.Verify(); }
public IActionResult CalculateAmount([FromBody] EstimationModel estimation) { var user = _iuserService.GetByName(estimation.Username); if (user == null) { return(BadRequest(new { message = "Invalid Request" })); } decimal discount = user.Discount != null ? user.Discount.Percentage : decimal.Zero; var Amount = _iuserService.CalculateFinalAmount(estimation.Rate, estimation.Weight, discount); return(Ok(new { Total = Amount, Discount = new { Percentage = 0 }, }));; }
public HttpResponseMessage Save(EstimationModel model) { try { var shortTermEstimationList = _service.SaveEstimation(model); if (shortTermEstimationList) { return(Request.CreateResponse(HttpStatusCode.OK, shortTermEstimationList)); } else { string message = "Error Saving Data"; return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, message)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public HttpResponseMessage GetOrderID(EstimationModel model, Guid id) { try { var getorder = _service.GetOrderIDByID(model, id); if (getorder != null) { return(Request.CreateResponse(HttpStatusCode.OK, getorder)); } else { string message = "Error in Getting Data"; return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, message)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
protected EstimationModel GetEstimationModel(string userName, string role, decimal goldPricePerGram, decimal weightInGram, decimal expectedTotalPrice) { var estimate = new EstimationModel { Customer = new CustomerModel(configuration) { UserName = userName, UserCategories = new List <string> { role } }, GoldPricePerGram = goldPricePerGram, WeightInGram = weightInGram }; var mock = new Mock <ILogger <EstimateBusiness> >(); IEstimateBusiness estimationBusiness = new EstimateBusiness(mock.Object); estimationBusiness.CalculateEstimate(estimate); return(estimate); }
public EstimationModel GetEstimationByEstimationNo(BaseViewModel model, string EstimationID) { EstimationModel estimationModel = new EstimationModel(); Estimation estimation; try { Guid Id = new Guid(EstimationID); estimation = _orderDetailsRepository.GetEstimationByEstimationID(Id); estimationModel = Mapper.Map <Estimation, EstimationModel>(estimation); estimationModel.CurrentUserID = model.CurrentUserID; estimationModel.CurrentCulture = model.CurrentCulture; estimationModel.EstimateRouteName = Utility.GetPropertyValue(estimation.Master_EstimationRoutes, "Name", model.CurrentCulture) == null ? string.Empty : Utility.GetPropertyValue(estimation.Master_EstimationRoutes, "Name", model.CurrentCulture).ToString(); estimationModel.ClientName = Utility.GetPropertyValue(estimation.Company, "Name", model.CurrentCulture) == null ? string.Empty : Utility.GetPropertyValue(estimation.Company, "Name", model.CurrentCulture).ToString(); estimationModel.OutwardSalesName = Utility.GetPropertyValue(estimation.Employee, "Name", model.CurrentCulture) == null ? string.Empty : Utility.GetPropertyValue(estimation.Employee, "Name", model.CurrentCulture).ToString(); estimationModel.CoordinatorName = Utility.GetPropertyValue(estimation.Employee, "Name", model.CurrentCulture) == null ? string.Empty : Utility.GetPropertyValue(estimation.Employee, "Name", model.CurrentCulture).ToString(); estimationModel.SalesPersonName = Utility.GetPropertyValue(estimation.Employee, "Name", model.CurrentCulture) == null ? string.Empty : Utility.GetPropertyValue(estimation.Employee, "Name", model.CurrentCulture).ToString(); estimationModel.LargeSalesName = Utility.GetPropertyValue(estimation.Employee, "Name", model.CurrentCulture) == null ? string.Empty : Utility.GetPropertyValue(estimation.Employee, "Name", model.CurrentCulture).ToString(); estimationModel.TotalWithTax = estimation.TotalWithTax; //estimationModel.BusinessCategoryName = Utility.GetPropertyValue(estimation.master, "Name", model.CurrentCulture) == null ? string.Empty : // Utility.GetPropertyValue(estimation.Employee, "Name", model.CurrentCulture).ToString(); } catch (Exception ex) { IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "OrderDetails", message); throw new Exception(message); } finally { _sqlConnService.CloseConnection(); } return(estimationModel); }
public async Task <HttpResponseMessage> Estimate(Guid id, [FromBody] EstimationModel estimationModel) { //lock (estimationLock) //{ var game = await gameRepository.Get(id).ConfigureAwait(false); var player = Thread.CurrentPrincipal.Identity.Name; var estimation = new Estimation(estimationModel.Value, player); if (game.Estimate(estimation) is Failure <string> f) { return(new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new StringContent(f.Data) }); } gameRepository.Update(game).Wait(); return(new HttpResponseMessage(HttpStatusCode.OK)); //} }
public HttpResponseMessage Save(EstimationModel model) { try { IEstimationService service = new EstimationService(); var result = service.SaveEstimation(model); if (result) { new EmailService().SendEstimationRequestEmailToAdmin(model); return(Request.CreateResponse(HttpStatusCode.OK, result)); } else { string message = "Error Saving Data"; return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, message)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public void CalculateEstimate(EstimationModel estimate) { var calculatedEstimate = CalculateEstimateWithoutDiscount(estimate.GoldPricePerGram, estimate.WeightInGram); try { logger.LogInformation("Started Calculating Estimate"); if (estimate.Customer.UserCategories.Contains(Entities.UserCategory.Privileged.ToString())) { calculatedEstimate = CalculateEstimateWithDiscount(calculatedEstimate, estimate.Customer.DiscountPercentApplicable); } else { calculatedEstimate = CalculateEstimateWithDiscount(calculatedEstimate, estimate.Customer.DiscountPercentApplicable); } estimate.TotalPrice = calculatedEstimate; } catch (Exception ex) { logger.LogError(ex.Message); throw new ExstimationApplicationBusinessException(ex.Message); } }
public List <EstimationModel> DeleteNarrationEstimation(EstimationModel model) { try { var estimation = _dbContext.Estimations.Find(model.ID); if (estimation != null) { estimation.IsDeleted = true; _dbContext.Entry(estimation).State = EntityState.Modified; _dbContext.SaveChanges(); } } catch (Exception ex) { IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(model.CurrentUserID, "DTPEstimation", message); throw new Exception(message); } BaseModel.CurrentCulture = model.CurrentCulture; BaseModel.CurrentUserID = model.CurrentUserID; return(GetAllNarrationEstimationList(BaseModel)); }
public HttpResponseMessage GenerateQuotationPdf(EstimationModel model) { try { var viewData = new System.Web.Mvc.ViewDataDictionary { { "Estimation", model } }; var html = RenderViewToString("Estimation", "~/Views/Template/TranslationEstimation.cshtml", viewData); var buffer = HiWork.Utils.PdfHelper.HtmlToPdf(html, ""); var result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new StreamContent(new MemoryStream(buffer)); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); result.Content.Headers.ContentLength = buffer.Length; //result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); //result.Content.Headers.ContentDisposition.FileName = "TranslationEstimation_" + DateTime.Now.ToShortDateString() + ".pdf"; result.Content.Headers.Add("FileName", "TranslationEstimation_" + DateTime.Now.ToShortDateString() + ".pdf"); result.Content.Headers.Add("Access-Control-Expose-Headers", "FileName"); return(result); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public List <OrderModel> GetOrderIDByID(EstimationModel model, Guid id) { List <OrderModel> datalist = new List <OrderModel>(); List <Order> MasterDataList; OrderModel datatemplate; try { MasterDataList = _dbContext.Orders.ToList(); foreach (Order a in MasterDataList) { if (a.EstimationID == id) { datatemplate = Mapper.Map <Order, OrderModel>(a); datalist.Add(datatemplate); } } return(datalist); } catch (Exception ex) { throw new Exception(ex.Message); } }
protected string GetEstimationDataText(EstimationModel estimation) { string dataText = string.Concat("GoldPricePerGram: ", estimation.GoldPricePerGram, "\nWeightInGram: ", estimation.WeightInGram, "\nTotalPrice: ", estimation.TotalPrice); return(dataText); }
public abstract PrintModel Print(EstimationModel estimation);