public CommonResponseViewModel UpdateCustomer(CustomerViewModel customerVM) { CommonResponseViewModel response = new CommonResponseViewModel(); try { using (_dbContext = new AccountdbContext()) { var customer = _dbContext.Customer.Where(c => c.CustId.Equals(customerVM.id)).FirstOrDefault(); if (customer != null) { customer.FirstName = customerVM.firstName; customer.MiddleName = customerVM.middleName; //customer.NickName = customerVM.nickName; customer.LastName = customerVM.lastName; customer.Mobile = customerVM.mobile; customer.ReferredBy = customerVM.referredBy; customer.CreatedBy = customerVM.createdBy; customer.ModifiedBy = customerVM.modifiedBy; customer.ModifiedDate = DateTime.Now; _dbContext.Update(customer); var customerDetails = _dbContext.CustomerDetails.Where(c => c.CustId.Equals(customerVM.id)).FirstOrDefault(); if (customerDetails != null) { customerDetails.CustId = customerVM.id; customerDetails.AlternateMobile = customerVM.alternateMobile; customerDetails.HomePhone = customerVM.homePhone; customerDetails.OfficePhone = customerVM.officePhone; customerDetails.Email = customerVM.email; customerDetails.Address = customerVM.address; customerDetails.City = customerVM.city; customerDetails.State = customerVM.state; customerDetails.ShopName = customerVM.shopName; customerDetails.ShopLocation = customerVM.shopLocation; _dbContext.Update(customerDetails); } _dbContext.SaveChanges(); response.isSuccess = true; } } } catch (Exception ex) { throw ex; } return(response); }
public CommonResponseViewModel UpdateVendor(VendorViewModel vendorVM) { CommonResponseViewModel response = new CommonResponseViewModel(); try { using (_dbContext = new AccountdbContext()) { var vendor = _dbContext.Vendor.Where(v => v.VendorId.Equals(vendorVM.id)).FirstOrDefault(); if (vendor != null) { vendor.FirstName = vendorVM.firstName; vendor.MiddleName = vendorVM.middleName; //vendor.NickName = vendorVM.nickName; vendor.LastName = vendorVM.lastName; vendor.MobileNo = vendorVM.mobile; vendor.ReferredBy = vendorVM.referredBy; vendor.CreatedBy = vendorVM.createdBy; vendor.ModifiedBy = vendorVM.modifiedBy; vendor.ModifiedDate = DateTime.Now; _dbContext.Update(vendor); var vendorDetails = _dbContext.VendorDetails.Where(c => c.VendorId.Equals(vendorVM.id)).FirstOrDefault(); if (vendorDetails != null) { vendorDetails.VendorId = vendorVM.id; vendorDetails.AlternateMobile = vendorVM.alternateMobile; vendorDetails.HomePhone = vendorVM.homePhone; vendorDetails.Email = vendorVM.email; vendorDetails.Address = vendorVM.address; vendorDetails.City = vendorVM.city; vendorDetails.State = vendorVM.state; _dbContext.Update(vendorDetails); } _dbContext.SaveChanges(); response.isSuccess = true; } } } catch (Exception ex) { throw ex; } return(response); }
public CommonResponseViewModel UpdateExpense(ExpenseViewModel expenseVM) { var responseVM = new CommonResponseViewModel(); try { bool isDuplicate = CheckIsDuplicate(expenseVM); if (isDuplicate) { responseVM.message = "Expense Name already exists"; return(responseVM); } using (_dbContext = new AccountdbContext()) { var expenseDBModel = _dbContext.Expenses.Where(e => e.ExpenseId.Equals(expenseVM.id)).FirstOrDefault(); if (expenseDBModel != null) { ConstructExpenseDBModel(expenseVM, ref expenseDBModel, true); _dbContext.Update(expenseDBModel); _dbContext.SaveChanges(); responseVM.isSuccess = true; } } } catch (Exception ex) { throw ex; } return(responseVM); }