public async Task <ActionResult> Edit(UserViewModel model) { if (ModelState.IsValid) { AspNetUser aspNetUser = await db.AspNetUsers.FindAsync(model.Id); if (aspNetUser != null) { //remove all previous roles var roles = await UserManager.GetRolesAsync(aspNetUser.Id); await UserManager.RemoveFromRolesAsync(aspNetUser.Id, roles.ToArray()); //add user in new roles foreach (String roleName in model.UserSelectedRoles) { //Assign Role to user await UserManager.AddToRoleAsync(aspNetUser.Id, roleName); } } db.Entry(aspNetUser).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } else { List <UserLevel> UserLevels = db.UserLevels.ToList(); ViewBag.Level = UserLevels; } return(View(model)); }
public JsonResult SaveProductStock(ProductStock stock) { POS.Helper.AppHelper.ReturnMessage retMessage = new AppHelper.ReturnMessage(); POSEntities db = new POSEntities(); retMessage.IsSuccess = true; if (stock.ProductQtyId > 0) { db.Entry(stock).State = EntityState.Modified; retMessage.Messagae = "Update Success!"; } else { db.ProductStocks.Add(stock); retMessage.Messagae = "Save Success!"; } try { db.SaveChanges(); } catch (Exception) { retMessage.IsSuccess = false; } return(Json(retMessage, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveUser(User user) { POSEntities db = new POSEntities(); bool isSuccess = true; if (user.UserId > 0) { db.Entry(user).State = EntityState.Modified; } else { user.Status = 1; user.Password = AppHelper.GetMd5Hash(user.Password); db.Users.Add(user); } try { db.SaveChanges(); } catch (Exception) { isSuccess = false; } return(Json(isSuccess, JsonRequestBehavior.AllowGet)); }
public IHttpActionResult PutItem(string id, Item item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != item.ItemId) { return(BadRequest()); } db.Entry(item).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ItemExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <ActionResult> Edit([Bind(Include = "Id, Code, Name, Description, CategoryId, ImageURL, Price, VAT, DiscountType, DiscountValue, ValidFromDate, ValidToDate, IsDealItem_YN")] Item Item) { if (ModelState.IsValid) { db.Entry(Item).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(Item)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Code,Name,MenuItemId,InventoryItemId,Quantity")] Recipe recipe) { if (ModelState.IsValid) { db.Entry(recipe).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(recipe)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Code,Name,IsActive")] Vendor vendor) { if (ModelState.IsValid) { db.Entry(vendor).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(vendor)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,FirstName,LastName,PhoneNumber,Address")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(customer)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,RestaurantName,Address,Phone1,Phone2,DataSync")] Configuration configuration) { if (ModelState.IsValid) { db.Entry(configuration).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(configuration)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Code,Name,Barcode,Description,PackagingUnit,RecipeUnit,ReciptUnitPerPackage,SortOrder,ReOrderLevel,ReplenishLevel,TotalPackages,UpdateRecipeBalance,PackagePuchasePrice,PackageSellingPrice,Group,LocationId,VendorId")] InventoryItem inventoryItem) { if (ModelState.IsValid) { db.Entry(inventoryItem).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(inventoryItem)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Code,Name,SortOrder,ShelfLocation")] InventoryLocation inventoryLocation) { if (ModelState.IsValid) { db.Entry(inventoryLocation).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(inventoryLocation)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Code,Name,Description")] CategoryType ward) { if (ModelState.IsValid) { db.Entry(ward).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(ward)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Code,Name,ShortName,Factor,Dimension")] Unit unit) { if (ModelState.IsValid) { db.Entry(unit).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(unit)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,IsActive_YN")] Country country) { if (ModelState.IsValid) { db.Entry(country).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(country)); }
public async Task <ActionResult> Edit([Bind(Include = "LevelId,LevelName,Description,IsActive_YN")] UserLevel userLevel) { if (ModelState.IsValid) { db.Entry(userLevel).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(userLevel)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,CountryId,StateId,IsActive_YN")] City city) { if (ModelState.IsValid) { db.Entry(city).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CountryId = new SelectList(db.Countries, "Id", "Name", city.CountryId); ViewBag.StateId = new SelectList(db.States, "Id", "Name", city.StateId); return(View(city)); }
public ActionResult Edit(Developer developer) { developer.IsActive = true; developer.LastModified = GetDate; developer.LastModifiedBy = GetUserId; if (ModelState.IsValid) { _db.Entry(developer).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(developer)); }
public ActionResult Edit(Sales_Person sales_Person) { sales_Person.IsActive = true; sales_Person.LastModified = GetDate; sales_Person.LastModifiedBy = GetUserId; if (ModelState.IsValid) { _db.Entry(sales_Person).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sales_Person)); }
public ActionResult Edit(Units_Details units_Details) { units_Details.IsActive = true; units_Details.LastModified = GetDate; units_Details.LastModifiedBy = GetUserId; if (ModelState.IsValid) { _db.Entry(units_Details).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FK_DeveloperId = new SelectList(_db.Developers, "Id", "Name", units_Details.FK_DeveloperId); ViewBag.FK_Sales_PersonId = new SelectList(_db.Sales_Person, "Id", "Name", units_Details.FK_Sales_PersonId); return(View(units_Details)); }
public ActionResult Edit(string MenuId, string newName) { if (ModelState.IsValid) { Menu menuItem = db.Menus.Find(Convert.ToInt64(MenuId)); if (menuItem != null) { menuItem.Name = newName; menuItem.DisplayName = newName; db.Entry(menuItem).State = EntityState.Modified; db.SaveChangesAsync(); } } return(View()); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,DisplayName,LevelName,LevelId")] RoleViewModel roleVM) { if (ModelState.IsValid) { roleVM.setRoleName(roleVM.DisplayName, roleVM.LevelName); AspNetRole role = await db.AspNetRoles.FindAsync(roleVM.Id); role.Name = roleVM.Name; role.LevelId = roleVM.LevelId; db.Entry(role).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.Level = db.UserLevels; return(View(roleVM)); }
public JsonResult SaveBatch(Batch batch) { POS.Helper.AppHelper.ReturnMessage retMessage = new AppHelper.ReturnMessage(); POSEntities db = new POSEntities(); retMessage.IsSuccess = true; if (batch.BatchId > 0) { db.Entry(batch).State = EntityState.Modified; retMessage.Messagae = "Update Success!"; } else { batch.BatchName = batch.BatchName + db.Batches.Count(); var batchData = db.Batches.Where(x => x.BatchName.Equals(batch.BatchName)).SingleOrDefault(); if (batchData == null) { db.Batches.Add(batch); retMessage.Messagae = "Save Success!"; } else { retMessage.IsSuccess = false; retMessage.Messagae = "This batch already exist!Please refresh and again try!"; } } try { db.SaveChanges(); } catch (Exception) { retMessage.IsSuccess = false; } return(Json(retMessage, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveProduct(Product product) { POSEntities db = new POSEntities(); bool isSuccess = true; if (product.ProductId > 0) { db.Entry(product).State = EntityState.Modified; } else { db.Products.Add(product); } try { db.SaveChanges(); } catch (Exception) { isSuccess = false; } return(Json(isSuccess, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveCategory(Category cat) { POSEntities db = new POSEntities(); bool isSuccess = true; if (cat.CategoryId > 0) { db.Entry(cat).State = EntityState.Modified; } else { cat.Status = 1; db.Categories.Add(cat); } try { db.SaveChanges(); } catch (Exception) { isSuccess = false; } return(Json(isSuccess, JsonRequestBehavior.AllowGet)); }
//[ValidateAntiForgeryToken] public async Task <ActionResult> Create(OrderViewModel newOrder) { DateTime orderDatetime = newOrder.OrderDateTime.HasValue ? newOrder.OrderDateTime.Value : DateTime.Now; DbContextTransaction transaction = null; try { if (ModelState.IsValid) { var ShiftAStart = TimeSpan.Parse(System.Configuration.ConfigurationManager.AppSettings["ShiftAStart"]); var ShiftAEnd = TimeSpan.Parse(System.Configuration.ConfigurationManager.AppSettings["ShiftAEnd"]); var ShiftBStart = TimeSpan.Parse(System.Configuration.ConfigurationManager.AppSettings["ShiftBStart"]); var ShiftBEnd = TimeSpan.Parse(System.Configuration.ConfigurationManager.AppSettings["ShiftBEnd"]); string shift = "A"; if (ShiftAStart >= DateTime.Now.TimeOfDay && ShiftAEnd <= DateTime.Now.TimeOfDay) { shift = "A"; } else //if (ShiftBStart >= DateTime.Now.TimeOfDay && ShiftBEnd<= DateTime.Now.TimeOfDay) { shift = "B"; } transaction = db.Database.BeginTransaction(); var order = Mapper.Map <Order>(newOrder); if (order.Id == 0) { order.OrderDateTime = orderDatetime; order.Shift = shift; order.Code = await NextOrderNumber(); order.StatusId = (int)EOrderStatus.NEW; db.Orders.Add(order); } else { if (db.Invoices.Where(t => t.OrderId == newOrder.Id).Count() > 0) { if (db.Invoices.Where(t => t.OrderId == newOrder.Id).Count() > 0) { return(Json(new { success = true, responseText = "Order cannot be edited. Invoice has been generated for this order." }, JsonRequestBehavior.AllowGet)); } } order.OrderDateTime = orderDatetime; order.StatusId = (int)EOrderStatus.NEW; order.UpdatedOn = DateTime.Now; var delayedInvoice = db.SCWTimers.Where(t => t.OrderId == newOrder.Id).FirstOrDefault(); if (delayedInvoice != null) { db.SCWTimers.Remove(delayedInvoice); } order.Shift = shift; db.Entry(order).State = EntityState.Modified; var deleteStatus = db.Database.ExecuteSqlCommand($"DELETE FROM OrderDetail WHERE OrderId={order.Id}"); newOrder.OrderDetail.ForEach(t => t.Id = null); } var orderId = await db.SaveChangesAsync(); newOrder.OrderDetail.ForEach(t => t.OrderId = order.Id); foreach (var item in newOrder.OrderDetail) { var orderDetail = Mapper.Map <OrderDetail>(item); orderDetail.Item = null; db.OrderDetails.Add(orderDetail); } await db.SaveChangesAsync(); transaction.Commit(); return(Json(new { Id = order.Id, Code = order.Code, success = true, responseText = "Order saved succesfuly." }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { transaction.Rollback(); return(Json(new { success = false, responseText = $"{ex.Message}" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, responseText = "Please review selected item." }, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> SaveAsync(InvIssueDto vm) { try { if (ModelState.IsValid) { if (vm.listIssueDetailsToDelete.Count() > 0) { foreach (var item in vm.listIssueDetailsToDelete) { var objdelete = db.InvIssueDetails.Find(item); if (objdelete != null) { db.Entry(objdelete).State = EntityState.Deleted; await db.SaveChangesAsync(); } } } var objsave = new InvIssue() { Id = vm.Id, Description = vm.Description, IssueBy = vm.IssueBy, IssueTo = vm.IssueTo, IssueDate = vm.IssueDate.ToString(), IssueNo = vm.IssueNo, IssuePlace = ((IssuePlace)vm.IssuePlaceId).ToString() }; if (objsave.Id > 0 && vm.ObjectState != (int)ObjectState.Deleted) { vm.ObjectState = (int)ObjectState.Modified; } if (objsave.Id <= 0 && vm.ObjectState != (int)ObjectState.Deleted) { vm.ObjectState = (int)ObjectState.Added; } switch (vm.ObjectState) { case (int)ObjectState.Added: db.InvIssues.Add(objsave); await db.SaveChangesAsync(); break; case (int)ObjectState.Modified: db.Entry(objsave).State = EntityState.Modified; await db.SaveChangesAsync(); break; case (int)ObjectState.Deleted: var details = db.InvIssueDetails.Where(x => x.InvIssueId == objsave.Id).ToList(); foreach (var item in details) { var invissuedetail = await db.InvIssueDetails.FindAsync(item.Id); db.Entry(invissuedetail).State = EntityState.Deleted; db.SaveChanges(); } db.Entry(objsave).State = EntityState.Deleted; await db.SaveChangesAsync(); break; } vm.Id = objsave.Id; vm.listIssueDetail = await SaveDetailAsync(vm); var result = new { result = vm }; return(Json(result)); } else { var result = new { result = false }; return(Json(result)); } } catch (Exception ex) { return(Json(null)); } }
public async Task <JsonResult> SaveAsync(InvReceiptDto vm) { try { if (vm.listDetailToDelete.Count() > 0) { foreach (var item in vm.listDetailToDelete) { var objdelete = db.InvReceiptDetails.Find(item); if (objdelete != null) { db.Entry(objdelete).State = EntityState.Deleted; await db.SaveChangesAsync(); } } } var objsave = new InvReceipt() { Id = vm.Id, Description = vm.Description, ReceiptDate = vm.ReceiptDate, ReceiptNo = vm.ReceiptNo, ReceivedBy = vm.ReceivedById, VendorId = vm.VendorId, ReceivedPlace = ((RecievePlace)vm.ReceivedPlaceId).ToString() }; if (objsave.Id > 0 && vm.ObjectState != (int)ObjectState.Deleted) { vm.ObjectState = (int)ObjectState.Modified; } if (objsave.Id <= 0 && vm.ObjectState != (int)ObjectState.Deleted) { vm.ObjectState = (int)ObjectState.Added; } switch (vm.ObjectState) { case (int)ObjectState.Added: db.InvReceipts.Add(objsave); await db.SaveChangesAsync(); break; case (int)ObjectState.Modified: db.Entry(objsave).State = EntityState.Modified; await db.SaveChangesAsync(); break; case (int)ObjectState.Deleted: var returndetails = db.InvReceiptDetails.Where(x => x.InvReceiptId == objsave.Id).ToList(); foreach (var item in returndetails) { var invReturndetail = await db.InvReceiptDetails.FindAsync(item.Id); db.Entry(invReturndetail).State = EntityState.Deleted; db.SaveChanges(); } db.Entry(objsave).State = EntityState.Deleted; await db.SaveChangesAsync(); break; } vm.Id = objsave.Id; vm.listDetail = await SaveDetailAsync(vm); var result = new { result = vm }; return(Json(result)); } catch (Exception ex) { return(Json(null)); } }