public ActionResult EditContact([Bind(Include = "Id,customer_id,first_name,last_name,work_phone,mobile_phone,fax,contact_email")] Customer_Contact customer_Contact) { if (ModelState.IsValid) { db.Entry(customer_Contact).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", new { id = customer_Contact.customer_id })); } ViewBag.customer_id = new SelectList(db.Customers, "Id", "customer_company_name", customer_Contact.customer_id); ViewBag.ActionTitle = "Edit "; ViewBag.CustomerName = db.Customers.Find(customer_Contact.customer_id).customer_company_name; return(View(customer_Contact)); }
public ActionResult Add(int?id, int?Quantity) { string message = ""; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var inventory = db.Product_Inventory.Find(id); if (inventory == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (Quantity == null || Quantity == 0) { message = "Please insert quantity to update " + inventory.Product.product_name.ToString() + "'s Quantity."; } // if all info are valid if (id != null && Quantity != null) { inventory.unit_quantity += Convert.ToInt32(Quantity); db.Entry(inventory).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,ModeOfPaycheck,paycheck_date,payroll_id,payment_type,check_number,direct_deposit_number,payment_amount")] PaycheckModeModel paycheck) { // set old paycheck paycheck.SetPayroll(paycheck.payroll_id); Paycheck oldPaycheck = PaycheckModeModel.ToBase(paycheck); // assign fields to new paycheck var newPaycheck = dbBusiness.Paychecks.Find(oldPaycheck.Id); newPaycheck.paycheck_date = oldPaycheck.paycheck_date; newPaycheck.payroll_id = oldPaycheck.payroll_id; newPaycheck.payment_type = oldPaycheck.payment_type; newPaycheck.check_number = oldPaycheck.check_number; newPaycheck.direct_deposit_number = oldPaycheck.direct_deposit_number; newPaycheck.payment_amount = oldPaycheck.payment_amount; dbBusiness.Entry(newPaycheck).State = EntityState.Modified; var result = dbBusiness.SaveChanges(); if (result > 0) { return(RedirectToAction("Index")); } ViewBag.ActionTitle = "Edit "; return(View(paycheck)); }
public ActionResult Edit([Bind(Include = "Id,employee_id,period_begin,period_end")] Payroll payroll) { string errorMessage = ""; var oldPayroll = db.Payrolls.Find(payroll.Id); oldPayroll.CalculatePayroll(); if (ModelState.IsValid) { oldPayroll.InitializeTimesheets(); var newPayroll = db.Payrolls.Find(payroll.Id); newPayroll.period_begin = payroll.period_begin; newPayroll.period_end = payroll.period_end; newPayroll.total_hours = 0; newPayroll.subtotal = 0m; newPayroll.CalculatePayroll(); db.Entry(newPayroll).State = EntityState.Modified; var result = db.SaveChanges(); if (result > 0) { newPayroll.ChangeTimesheetsStatus(); return(RedirectToAction("Index")); } else { oldPayroll.ChangeTimesheetsStatus(); errorMessage = "Unable to modify this payroll. Please try again."; } } ViewBag.ErrorMessage = errorMessage; ViewBag.ActionTitle = "Edit "; return(View(payroll)); }
public ActionResult Edit([Bind(Include = "Id,product_name,product_short_description,product_long_description,product_note,product_unit_measure,product_unit_cost,product_unit_price,product_category_id,Product_Category")] Product product) { //if (ModelState.IsValid) //{ // db.Entry(product).State = EntityState.Modified; // db.SaveChanges(); // return RedirectToAction("Index"); //} var newProduct = db.Products.Find(product.Id); newProduct.product_name = product.product_name; newProduct.product_short_description = product.product_short_description; newProduct.product_long_description = product.product_long_description; newProduct.product_note = product.product_note; newProduct.product_unit_measure = product.product_unit_measure; newProduct.product_unit_cost = product.product_unit_cost; newProduct.product_unit_price = product.product_unit_price; newProduct.product_category_id = product.product_category_id; db.Entry(newProduct).State = EntityState.Modified; var result = db.SaveChanges(); if (result > 0) { return(RedirectToAction("Index")); } ViewBag.product_category_id = new SelectList(db.Product_Category, "Id", "category_name", product.product_category_id); ViewBag.ActionTitle = "Edit "; return(View(product)); }
public ActionResult SelectItem(int?id, int?deliveryScheduleID, int?Quantity) { var newDeliveryLI = db.Delivery_Lineitem.Find(id); if (newDeliveryLI != null) { if (Quantity != null && Quantity > newDeliveryLI.lineitem_unit_quantity) { ViewBag.ErrorMessage = "Please enter the quantity as equal or less than linvoice lineitem."; } else if (deliveryScheduleID != null && Quantity <= newDeliveryLI.lineitem_unit_quantity) { newDeliveryLI.delivery_schedule_id = Convert.ToInt32(deliveryScheduleID); // check quantity if (Quantity < newDeliveryLI.lineitem_unit_quantity) { var secondDeliveryLI = new Delivery_Lineitem(); secondDeliveryLI.product_inventory_id = newDeliveryLI.product_inventory_id; secondDeliveryLI.lineitem_unit_quantity = newDeliveryLI.lineitem_unit_quantity - Convert.ToInt32(Quantity); secondDeliveryLI.invoice_lineitem_id = newDeliveryLI.invoice_lineitem_id; db.Delivery_Lineitem.Add(secondDeliveryLI); } newDeliveryLI.lineitem_unit_quantity = Convert.ToInt32(Quantity); db.Entry(newDeliveryLI).State = EntityState.Modified; var result = db.SaveChanges(); if (result == 0) { return(View("Error")); } return(RedirectToAction("Edit", "Delivery_Schedule", new { id = deliveryScheduleID })); } else { ViewBag.ErrorMessage = "Something went wrong. Please try again."; } } var deliveryQ = db.Delivery_Lineitem.Where(dl => dl.delivery_schedule_id == null).OrderBy(dl => dl.Invoice_Lineitem.invoice_id).ToList(); foreach (var i in deliveryQ) { i.CalculateTotal(i.product_inventory_id); } ViewBag.DeliveryScheduleID = deliveryScheduleID; return(View(deliveryQ)); }
public ActionResult Edit([Bind(Include = "id,Name,Value,Address")] AspNetBusiness aspNetBusiness) { if (ModelState.IsValid) { db.Entry(aspNetBusiness).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aspNetBusiness)); }
public ActionResult Edit([Bind(Include = "Id,warehouse_employee_id,driver_employee_id,delivery_date,delivery_cost,is_delivered,invoice_id")] Delivery_Schedule delivery_Schedule) { if (ModelState.IsValid) { db.Entry(delivery_Schedule).State = EntityState.Modified; db.SaveChanges(); Session["DeliverySchedule"] = null; return(RedirectToAction("Index")); } return(View(delivery_Schedule)); }
public ActionResult Edit([Bind(Include = "Id,invoice_id,payment_total,payment_type,payment_date,payment_note")] Payment payment) { if (ModelState.IsValid) { db.Entry(payment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ActionTitle = "Edit "; return(View(payment)); }
public ActionResult Edit([Bind(Include = "Id,category_name")] Product_Category product_Category) { if (ModelState.IsValid) { db.Entry(product_Category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ActionTitle = "Edit "; return(View(product_Category)); }
public ActionResult Edit([Bind(Include = "Id,material_id,material_unit_measure,material_unit_quantity,material_unit_cost")] Material_Stock material_Stock) { if (ModelState.IsValid) { db.Entry(material_Stock).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.material_id = new SelectList(db.Materials, "Id", "material_name", material_Stock.material_id); return(View(material_Stock)); }
public ActionResult Edit([Bind(Include = "Id,equipment_name,equipment_short_description,equipment_long_description,equipment_note,equipment_cost,product_id,in_maintenance")] Equipment equipment) { if (ModelState.IsValid) { db.Entry(equipment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.product_id = new SelectList(db.Products, "Id", "product_name", equipment.product_id); return(View(equipment)); }
public ActionResult Edit([Bind(Include = "Id,product_inventory_id,lineitem_unit_quantity,invoice_id")] Invoice_Lineitem invoice_Lineitem, int?optionalID, int?lineitemID) { if (ModelState.IsValid) { db.Entry(invoice_Lineitem).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Edit", "invoices", new { id = optionalID })); } ViewBag.OptionalID = optionalID; ViewBag.LineitemID = lineitemID; return(View(invoice_Lineitem)); }
public ActionResult Edit([Bind(Include = "Id,material_name,material_description,material_note,product_id")] Material material) { if (ModelState.IsValid) { db.Entry(material).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.product_id = new SelectList(db.Products, "Id", "product_name", material.product_id); ViewBag.ActionTitle = "Edit "; return(View(material)); }
public ActionResult Edit([Bind(Include = "Id,employee_id,punch_in_time,punch_out_time,timesheet_date")] Timesheet timesheet) { timesheet.employee_id = User.Identity.GetUserId(); if (ModelState.IsValid) { db.Entry(timesheet).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.employee_id = new SelectList(db.AspNetUsers, "Id", "Email", timesheet.employee_id); ViewBag.ActionTitle = "Edit "; return(View(timesheet)); }
public ActionResult Edit([Bind(Include = "Id,equipment_id,maintenance_date,completion_eta,maintenance_cost,employee_id,maintenance_short_description,maintenance_long_description,maintenance_note")] Equipment_Maintenance equipment_Maintenance) { if (ModelState.IsValid) { db.Entry(equipment_Maintenance).State = EntityState.Modified; db.SaveChanges(); Session["EquipmentMaintenance"] = null; return(RedirectToAction("Index")); } equipment_Maintenance.AspNetUser = db.AspNetUsers.Find(equipment_Maintenance.employee_id); equipment_Maintenance.Equipment = db.Equipments.Find(equipment_Maintenance.equipment_id); return(View(equipment_Maintenance)); }
public ActionResult Edit([Bind(Include = "Id,product_id,unit_quantity,unit_per_package,per_package_cost,packaging_cost,per_package_price")] Product_Inventory product_Inventory) { if (ModelState.IsValid) { product_Inventory.CalculatePackage(); db.Entry(product_Inventory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.product_id = new SelectList(db.Products, "Id", "product_name", product_Inventory.product_id); ViewBag.ActionTitle = "Edit "; return(View(product_Inventory)); }
protected override void BeforeSave(Dictionary <string, string> dic, Base.Logic.Domain.S_UI_Form formInfo, bool isNew) { var list = new List <Dictionary <string, object> >(); var id = dic.GetValue("ID"); var normalValue = 0m; if (!string.IsNullOrEmpty(dic.GetValue("NormalValue"))) { normalValue = Convert.ToDecimal(dic.GetValue("NormalValue")); } var extraValue = 0m; if (!string.IsNullOrEmpty(dic.GetValue("AdditionalValue"))) { extraValue = Convert.ToDecimal(dic.GetValue("AdditionalValue")); } if ((normalValue == 0 && extraValue == 0)) { throw new Formula.Exceptions.BusinessException("每日工时不能为0"); } var user = FormulaHelper.GetUserInfoByID(dic.GetValue("UserID")); var employee = BusinessEntities.Set <T_Employee>().FirstOrDefault(d => d.UserID == user.UserID); var fo = FormulaHelper.CreateFO <WorkHourFO>(); //根据日期段判断 var startDate = dic.GetValue("WorkHourDateStart").Replace("T", " "); var endDate = dic.GetValue("WorkHourDateEnd").Replace("T", " "); var projectID = dic.GetValue("ProjectID"); var SubProjectCode = dic.GetValue("SubProjectCode"); var MajorCode = dic.GetValue("MajorCode"); var WorkContent = dic.GetValue("WorkContent"); var dateList = getWorkHourDate(startDate, endDate); //已存在工时数据 var userID = dic.GetValue("UserID"); var existList = this.BusinessEntities.Set <S_W_UserWorkHour>().Where(a => a.UserID == userID && dateList.Contains(a.WorkHourDate)).ToList(); foreach (var item in dateList) { var existNormalValue = existList.Where(a => a.WorkHourDate == item && (a.SupplementID != id || a.SupplementID == null)).Sum(a => a.NormalValue); var existExtraValue = existList.Where(a => a.WorkHourDate == item && (a.SupplementID != id || a.SupplementID == null)).Sum(a => a.AdditionalValue); if (!existNormalValue.HasValue) { existNormalValue = 0; } if (!existExtraValue.HasValue) { existExtraValue = 0; } //自动补全正班工日,加班工日不补全 var _normalValue = normalValue; if ((_normalValue + existNormalValue) > NormalHoursMax) { _normalValue = NormalHoursMax - existNormalValue.Value; } //throw new Formula.Exceptions.BusinessException("【" + item.ToShortDateString() + "】正常工时不能大于" + NormalHoursMax.ToString()); if ((extraValue + existExtraValue) > maxExtraHour) { throw new Formula.Exceptions.BusinessException("【" + item.ToShortDateString() + "】加班工时不能大于" + maxExtraHour.ToString()); } if ((_normalValue == 0 && extraValue == 0)) { continue; } var userWorkHour = existList.FirstOrDefault(d => d.SupplementID == id && d.UserID == user.UserID && d.WorkHourDate == item); if (userWorkHour == null || BusinessEntities.Entry <S_W_UserWorkHour>(userWorkHour).State == System.Data.EntityState.Deleted) { userWorkHour = BusinessEntities.Set <S_W_UserWorkHour>().Create(); userWorkHour.ID = FormulaHelper.CreateGuid(); userWorkHour.UserID = user.UserID; userWorkHour.UserName = user.UserName; userWorkHour.UserDeptID = user.UserOrgID; userWorkHour.UserDeptName = user.UserOrgName; userWorkHour.WorkHourDate = item; userWorkHour.UserCode = user.Code; if (employee != null) { userWorkHour.EmployeeID = employee.ID; } userWorkHour.State = "Create"; userWorkHour.IsConfirm = "0"; userWorkHour.IsStep1 = "0"; userWorkHour.IsStep2 = "0"; userWorkHour.CreateUser = CurrentUserInfo.UserName; userWorkHour.CreateUserID = CurrentUserInfo.UserID; userWorkHour.SupplementID = id; userWorkHour.BelongMonth = item.Month; userWorkHour.BelongYear = item.Year; userWorkHour.BelongQuarter = ((item.Month - 1) / 3) + 1; BusinessEntities.Set <S_W_UserWorkHour>().Add(userWorkHour); } if (userWorkHour.State != "Create") { throw new Formula.Exceptions.BusinessException("【" + userWorkHour.WorkHourDate.ToShortDateString() + "】补填的工时已经审批,无法修改"); } userWorkHour.ProjectChargerUser = dic.GetValue("ProjectChargerUser"); userWorkHour.ProjectChargerUserName = dic.GetValue("ProjectChargerUserName"); userWorkHour.ProjectCode = dic.GetValue("ProjectCode"); userWorkHour.ProjectDept = dic.GetValue("ProjectDept"); userWorkHour.ProjectDeptName = dic.GetValue("ProjectDeptName"); userWorkHour.ProjectID = projectID; userWorkHour.ProjectName = dic.GetValue("ProjectName"); userWorkHour.SubProjectCode = dic.GetValue("SubProjectCode"); userWorkHour.SubProjectName = dic.GetValue("SubProjectName"); userWorkHour.TaskWorkCode = dic.GetValue("TaskWorkCode"); userWorkHour.TaskWorkName = dic.GetValue("TaskWorkName"); userWorkHour.WorkContent = dic.GetValue("WorkContent"); userWorkHour.MajorCode = dic.GetValue("MajorCode"); userWorkHour.MajorName = dic.GetValue("MajorName"); userWorkHour.WorkHourType = dic.GetValue("WorkHourType"); userWorkHour.NormalValue = _normalValue; userWorkHour.AdditionalValue = extraValue; userWorkHour.WorkHourValue = _normalValue + extraValue; userWorkHour.WorkHourDay = fo.ConvertHourToDay(userWorkHour.WorkHourValue, workHourType, NormalHoursMax); } }
public ActionResult Create([Bind(Include = "Id,invoice_date,employee_id,customer_id")] Invoice invoice) { if (ModelState.IsValid && invoice.employee_id != null && invoice.customer_id != 0) { db.Invoices.Add(invoice); var result = db.SaveChanges(); if (result > 0) { var li = (List <Lineitem>)Session["InvoiceItems"]; foreach (var item in li) { // create invoice lineitem var invoiceLI = new Invoice_Lineitem() { product_inventory_id = item.product_inventory_id, lineitem_unit_quantity = item.lineitem_unit_quantity }; invoiceLI.invoice_id = db.Invoices.Max(i => i.Id); db.Invoice_Lineitem.Add(invoiceLI); db.SaveChanges(); // create delivery lineitem queue var deliveryLI = new Delivery_Lineitem() { product_inventory_id = item.product_inventory_id, lineitem_unit_quantity = item.lineitem_unit_quantity }; deliveryLI.invoice_lineitem_id = db.Invoice_Lineitem.Max(i => i.Id); db.Delivery_Lineitem.Add(deliveryLI); db.SaveChanges(); // update product inventory quantity var productInventory = db.Product_Inventory.Find(item.product_inventory_id); productInventory.unit_quantity -= item.lineitem_unit_quantity; db.Entry(productInventory).State = EntityState.Modified; db.SaveChanges(); } } Session["InvoiceItems"] = null; Session["CurrentInvoice"] = null; return(RedirectToAction("Index")); } if (invoice.employee_id != null || invoice.employee_id != "") { invoice.AspNetUser = db.AspNetUsers.Find(invoice.employee_id); } if (invoice.customer_id != 0) { invoice.Customer = db.Customers.Find(invoice.customer_id); } var employeeError = ""; var customerError = ""; if (invoice.employee_id == null) { employeeError = "Please select an employee."; } if (invoice.customer_id == 0) { customerError = "Please select a customer."; } ViewBag.EmployeeError = employeeError; ViewBag.CustomerError = customerError; ViewBag.ActionTitle = "Create "; Session["CurrentInvoice"] = invoice; return(View(invoice)); }