public async Task <IActionResult> Create(WorkOrder model) { if (!ModelState.IsValid) { return(View(model)); } ViewBag.Success = ""; ViewBag.Error = ""; try{ var apiModel = new APIEmpIdModel <WorkOrder>(); apiModel.EmployeeId = int.Parse(User.Claims.Single(c => c.Type == "userid").Value); model.VAT = (DateTime.Today < July01_2020) ? (byte)5 : (byte)15; apiModel.Model = model; var result = await api.Post <APIEmpIdModel <WorkOrder>, int>("WorkOrder/", apiModel); if (result > 0) { return(RedirectToAction("Details", new{ id = result })); } else { ViewBag.Error = "Error saving WorkOrder"; } } catch (Exception ex) { ViewBag.Error = "Error saving WorkOrder: " + ex.Message; } return(View(model)); }
public int Add(APIEmpIdModel <Materials> model) { try { //var queryBuilder = new StringBuilder() // .Append("insert into materials ") // .Append("(code,name,specification,quantity,shelfnumber) ") // .Append("values ") // .Append($"('{newMaterial.Code}','{newMaterial.Name}', ") // .Append($"'{newMaterial.Specification}',0,'{newMaterial.ShelfNumber}');") // .Append("SELECT LAST_INSERT_ID();") // ; //var query = queryBuilder.ToString(); //return dbContext.Execute<int>(query); var materialId = dbContext.Get <int>(MaterialsQueries.Insert, DataHelper.ExtractParameters(model.Model)); if (materialId > 0) { var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, materialId, EventTypes.MaterialsCreate); dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent)); return(materialId); } else { throw new System.Exception("Error adding Material!"); } } catch (System.Exception ex) { throw; } }
public bool UpdateStatus(APIEmpIdModel <UpdateWorkOrderStatusModel> model) { var query = WorkOrderQueries.UpdateStatus; var parameters = DataHelper.ExtractParameters(new { StatusId = model.Model.Status, Id = model.Model.WorkOrderId }); dbContext.ExecuteNonQuery(query, parameters); EventTypes eventType = 0; switch (model.Model.Status) { case 1: eventType = EventTypes.WorkOrderDrafted; break; case 2: eventType = EventTypes.WorkOrderCreate; break; case 3: eventType = EventTypes.WorkOrderCancelled; break; case 4: eventType = EventTypes.WorkOrderComplete; break; } var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, model.Model.WorkOrderId, eventType); dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent)); return(true); }
public int Insert(APIEmpIdModel <WorkOrder> model) { try { var proposalService = new ProposalService(dbContext); var proposal = proposalService.GetProposalById(model.Model.ProposalId); model.Model.BusinessPartnerId = proposal.BusinessPartnerId; model.Model.BusinessPartnerContactId = proposal.BusinessPartnerContactId; var query = WorkOrderQueries.Add; var parameters = DataHelper.ExtractParameters(model.Model); var workorderId = dbContext.Execute <int>(query, parameters); var queryLines = WorkOrderQueries.CopyItemsFromProposal; var parametersLines = DataHelper.ExtractParameters(new { WorkOrderId = workorderId, ProposalId = model.Model.ProposalId }); dbContext.ExecuteNonQuery(queryLines, parametersLines); if (proposal.Discount.HasValue) { var discountModel = new DiscountView { Discount = proposal.Discount.Value, WorkOrderId = workorderId }; var res = ApplyDiscount(discountModel); } var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, workorderId, EventTypes.WorkOrderDrafted); dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent)); return(workorderId); } catch (Exception ex) { throw ex; } }
public int UpdateProposalItems(APIEmpIdModel <ProposalItemsUpdateModel> model) { var queries = new List <QueryWithParameters>(); var queryUpdateProposalItem = ProposalQueries.UpdateProposalItems; var proposalId = model.Model.Items.FirstOrDefault().ProposalId; foreach (var item in model.Model.Items) { if (item.Id == 0) { dbContext.ExecuteNonQuery(ProposalQueries.AddProposalItem, DataHelper.ExtractParameters(item)); } else { dbContext.ExecuteNonQuery(queryUpdateProposalItem, DataHelper.ExtractParameters(item)); } } foreach (var item in model.Model.DeletedItems) { dbContext.ExecuteNonQuery(ProposalQueries.DeleteProposalItem, DataHelper.ExtractParameters(item)); } var updateQuery = ProposalQueries.UpdateQuote; var updateParams = DataHelper.ExtractParameters(new { TotalAmount = model.Model.TotalAmount, Discount = model.Model.Discount, ProposalId = proposalId }); dbContext.ExecuteNonQuery(updateQuery, updateParams); var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, proposalId, EventTypes.QuoteUpdate); dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent)); return(dbContext.Get <int>(ProposalQueries.GetQuoteRevisionNo, DataHelper.ExtractParameters(new { ProposalId = proposalId }))); }
internal bool LogPrintEvent(APIEmpIdModel <int> model) { var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, model.Model, EventTypes.InvoicePrinted); dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent)); return(true); }
public async Task <IActionResult> Create(Materials model) { try { if (!ModelState.IsValid) { return(View(model)); } var isMaterialCodeDuplicated = await api.Get <Materials>($"materials/getbycode/{model.Code}"); if (isMaterialCodeDuplicated != null) { //Code Duplicated ModelState.AddModelError("Code", "Code already exist!"); return(View(model)); } var apiModel = new APIEmpIdModel <Materials>(); apiModel.EmployeeId = int.Parse(User.Claims.Single(c => c.Type == "userid").Value); apiModel.Model = model; var materialId = await api.Post <APIEmpIdModel <Materials>, int>("materials/", apiModel); return(RedirectToAction("List")); } catch (Exception ex) { ViewBag.Error = $"Error: <br />Message: {ex.Message}<br />Inner Exception: {ex.InnerException}"; return(View(model)); } }
public async Task <IActionResult> LogPrintEvent(int id) { var apiModel = new APIEmpIdModel <int>(); apiModel.EmployeeId = int.Parse(User.Claims.Single(c => c.Type == "userid").Value); apiModel.Model = id; var result = await api.Post <APIEmpIdModel <int>, bool>("WorkOrder/LogPrintEvent", apiModel); return(Json(result)); }
public async Task <IActionResult> AddSupplierPayment([FromBody] AddSupplierPaymentModel model) { var apiModel = new APIEmpIdModel <AddSupplierPaymentModel>(); apiModel.EmployeeId = int.Parse(User.Claims.Single(c => c.Type == "userid").Value); apiModel.Model = model; var result = await api.Post <APIEmpIdModel <AddSupplierPaymentModel>, bool>("PurchaseOrder/AddSupplierPayment", apiModel); return(Json(result)); }
public bool Receive([FromBody] APIEmpIdModel <PurchaseOrderDetailedView> model) { try{ db.SetPurchaseOrderReceiving(model); return(true); } catch (Exception ex) { throw; } }
public bool Confirm(APIEmpIdModel <int> id) { try { return(db.ConfirmPurchaseOrder(id)); } catch (Exception) { throw; } }
public int Post([FromBody] APIEmpIdModel <Materials> value) { try { return(db.Add(value)); } catch (Exception) { throw; } }
public int UpdateQuote([FromBody] APIEmpIdModel <ProposalItemsUpdateModel> value) { try { return(db.UpdateProposalItems(value)); } catch (Exception e) { throw e; } }
public int Post([FromBody] APIEmpIdModel <ProposalVM> value) { try { return(db.InsertProposal(value)); } catch (Exception) { throw; } }
public bool ConfirmPurchaseOrder(APIEmpIdModel <int> model) { var query = PurchaseOrderQueries.UpdatePurchaseOrderToConfirmed; var parameters = DataHelper.ExtractParameters(new{ Id = model.Model }); dbContext.ExecuteNonQuery(query, parameters); var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, model.Model, EventTypes.PurchaseOrderConfirm); dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent)); return(true); }
public int Post([FromBody] APIEmpIdModel <WorkOrder> value) { try { return(db.Insert(value)); } catch (Exception) { throw; } }
public bool UpdateInvoice([FromBody] APIEmpIdModel <WorkOrderItemsUpdateModel> value) { try { return(db.UpdateWorkOrderItems(value)); } catch (Exception e) { throw e; } }
public bool LogPrintEvent([FromBody] APIEmpIdModel <int> value) { try { return(db.LogPrintEvent(value)); } catch (Exception e) { throw e; } }
public bool UpdateStatus([FromBody] APIEmpIdModel <UpdateWorkOrderStatusModel> value) { try { return(db.UpdateStatus(value)); } catch (Exception) { throw; } }
public bool AddCustomerPayment([FromBody] APIEmpIdModel <CustomerPayments> value) { try { return(db.AddCustomerPayment(value)); } catch (Exception) { throw; } }
public int Post([FromBody] APIEmpIdModel <PurchaseOrderSimpleView> value) { try { return(db.InsertPurchaseOrderDraft(value)); } catch (Exception) { throw; } }
public bool AddMaterialsUse([FromBody] APIEmpIdModel <WorkOrderMaterials> value) { try { return(db.AddMaterialUse(value)); } catch (Exception) { throw; } }
public bool AddSupplierPayment(APIEmpIdModel <AddSupplierPaymentModel> model) { var queryAddPayment = PurchaseOrderQueries.InsertSupplierPayment; var parametersAddPayment = DataHelper.ExtractParameters(model.Model); var supplierPaymentId = dbContext.Execute <int>(queryAddPayment, parametersAddPayment); if (supplierPaymentId > 0) { var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, supplierPaymentId, EventTypes.SupplierPaymentAdd); dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent)); } return(true); }
public async Task <IActionResult> Confirm([FromBody] SimpleModel <int> model) { var apiModel = new APIEmpIdModel <int>(); apiModel.EmployeeId = int.Parse(User.Claims.Single(c => c.Type == "userid").Value); apiModel.Model = model.Value; var result = await api.Post <APIEmpIdModel <int>, bool>("PurchaseOrder/Confirm", apiModel); //var result=await api.Get<bool>($"PurchaseOrder/Confirm/{id}"); //return RedirectToAction("Confirmed",new{id=model}); return(Json(result)); }
public bool AddCustomerPayment(APIEmpIdModel <CustomerPayments> model) { var query = WorkOrderQueries.InsertCustomerPayment; var parameters = DataHelper.ExtractParameters(model.Model); dbContext.ExecuteNonQuery(query, parameters); var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, model.Model.WorkOrderId, EventTypes.CustomerPaymentAdd); dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent)); return(true); }
public async Task <IActionResult> Receive([FromBody] PurchaseOrderDetailedView model) { var apiModel = new APIEmpIdModel <PurchaseOrderDetailedView>(); apiModel.EmployeeId = int.Parse(User.Claims.Single(c => c.Type == "userid").Value); apiModel.Model = model; var result = await api.Post <APIEmpIdModel <PurchaseOrderDetailedView>, bool>("PurchaseOrder/Receive", apiModel); //var result = await api.Post<PurchaseOrderDetailedView,bool>("PurchaseOrder/Receive",model); //return RedirectToAction("List"); return(Json(result)); }
public bool AddMaterialUse(APIEmpIdModel <WorkOrderMaterials> model) { var query = WorkOrderQueries.AddMaterialUse; var parameters = DataHelper.ExtractParameters(new{ MaterialId = model.Model.MaterialId, Units = model.Model.Units, WorkOrderId = model.Model.WorkOrderId }); dbContext.ExecuteNonQuery(query, parameters); var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, model.Model.WorkOrderId, EventTypes.MaterialsConsumptionAdd); dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent)); return(true); }
public bool AddSupplierPayment([FromBody] APIEmpIdModel <AddSupplierPaymentModel> model) { try { var add = db.AddSupplierPayment(model); //var supplierPayments = db.GetSupplierPaymentsByPurchaseOrder(value.PurchaseOrderId); //return Json(supplierPayments.ToList()); return(true); } catch (Exception) { throw; } }
public async Task <IActionResult> AddCustomerPayment([FromBody] CustomerPayments model) { try{ var apiModel = new APIEmpIdModel <CustomerPayments>(); apiModel.EmployeeId = int.Parse(User.Claims.Single(c => c.Type == "userid").Value); apiModel.Model = model; var result = await api.Post <APIEmpIdModel <CustomerPayments>, bool>("WorkOrder/AddCustomerPayment", apiModel); return(Json(result)); } catch (Exception ex) { throw ex; } }
public int Add(APIEmpIdModel <Suppliers> model) { var supplierId = dbContext.Get <int>(SupplierQueries.Insert, DataHelper.ExtractParameters(model.Model)); if (supplierId > 0) { var erpEvent = new ERPEventHelper().GetEventModel(model.EmployeeId, supplierId, EventTypes.SuppliersCreate); dbContext.ExecuteNonQuery(EventQueries.EventInsert, DataHelper.ExtractParameters(erpEvent)); return(supplierId); } else { throw new System.Exception("Error adding Supplier!"); } }