//-> New public ActionResult New() { var record = new SaleOrderViewDTO(); record.date = DateTime.Now.ToShortDateString(); record.requiredDate = DateTime.Now.ToShortDateString(); record.mode = ConstantHelper.MODE_NEW; return(View(record)); }
//-> SelectByID public async Task <SaleOrderViewDTO> SelectByID(int id, bool _lock = false) { var session = HttpContext.Current.Session; UserViewDTO user = (UserViewDTO)session["user"]; int _user = 0; if (user != null) { _user = user.id; if (user.user_Profile == 1) { _user = -1; } } else { return(new SaleOrderViewDTO()); } var record = await db.tblSaleOrders.FirstOrDefaultAsync(x => x.deleted == null && x.id == id //var record = await db.vSaleOrders.FirstOrDefaultAsync(x => x.slor_Deleted == null && x.slor_SaleOrderID == id && //&&(_user == -1 ? 1 == 1 : _user == x.cust_UserID) ); if (_user != -1) { var cust = await db.tblCustomers.FirstOrDefaultAsync(x => x.id == record.customerID); if (cust != null) { if (cust.cust_UserID != _user) { return(new SaleOrderViewDTO()); } } } if (record == null) { return(new SaleOrderViewDTO()); } //throw new HttpException((int)HttpStatusCode.NotFound, "NotFound"); if (_lock) { if (record.slor_LockBy != null) { if (record.slor_LockBy != user.id) { var tt = new SaleOrderViewDTO(); tt.status = "_inuse"; tt.code = record.code; var _u = await db.tblUsers.FirstOrDefaultAsync(x => x.id == record.slor_LockBy); if (_u != null) { tt.product = _u.userName; } return(tt); } } record.slor_LockBy = user.id; record.slor_LockOn = DateTime.Now; await db.SaveChangesAsync(); } var saleOrderDTO = MappingHelper.MapDBClassToDTO <tblSaleOrder, SaleOrderViewDTO>(record); saleOrderDTO.customer = await new CustomerHandler().SelectByID(int.Parse(record.customerID.ToString())); saleOrderDTO.items = await GetLineItems(id); return(saleOrderDTO); }