public Int32 postStockCount() { try { Data.TrnStockCount newStockCount = new Data.TrnStockCount(); newStockCount.PeriodId = SalesId(); newStockCount.StockCountDate = DateTime.Today; newStockCount.StockCountNumber = "n/a"; newStockCount.Remarks = "n/a"; newStockCount.PreparedBy = UserId(); newStockCount.CheckedBy = UserId(); newStockCount.ApprovedBy = UserId(); newStockCount.IsLocked = 0; newStockCount.EntryUserId = UserId(); newStockCount.EntryDateTime = DateTime.Today; newStockCount.UpdateUserId = UserId(); newStockCount.UpdateDateTime = DateTime.Today; db.TrnStockCounts.InsertOnSubmit(newStockCount); db.SubmitChanges(); return(newStockCount.Id); } catch (Exception e) { return(0); } }
public Int32 insertStockCount(Models.TrnStockCount stockCount) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); var lastSCNumber = from d in db.TrnStockCounts.OrderByDescending(d => d.Id) where d.BranchId == currentBranchId() select d; var SCNumberResult = "0000000001"; if (lastSCNumber.Any()) { var SCNumber = Convert.ToInt32(lastSCNumber.FirstOrDefault().SCNumber) + 0000000001; SCNumberResult = zeroFill(SCNumber, 10); } Data.TrnStockCount newStockCount = new Data.TrnStockCount(); newStockCount.BranchId = currentBranchId(); newStockCount.SCNumber = SCNumberResult; newStockCount.SCDate = DateTime.Today; newStockCount.Particulars = "NA"; newStockCount.PreparedById = userId; newStockCount.CheckedById = userId; newStockCount.ApprovedById = userId; newStockCount.IsLocked = false; newStockCount.CreatedById = userId; newStockCount.CreatedDateTime = DateTime.Now; newStockCount.UpdatedById = userId; newStockCount.UpdatedDateTime = DateTime.Now; db.TrnStockCounts.InsertOnSubmit(newStockCount); db.SubmitChanges(); return(newStockCount.Id); } catch { return(0); } }
public HttpResponseMessage AddStockCount() { try { var currentUser = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var currentUserId = currentUser.FirstOrDefault().Id; var currentBranchId = currentUser.FirstOrDefault().BranchId; var userForms = from d in db.MstUserForms where d.UserId == currentUserId && d.SysForm.FormName.Equals("StockCountList") select d; if (userForms.Any()) { if (userForms.FirstOrDefault().CanAdd) { var defaultSCNumber = "0000000001"; var lastStockCount = from d in db.TrnStockCounts.OrderByDescending(d => d.Id) where d.BranchId == currentBranchId select d; if (lastStockCount.Any()) { var SCNumber = Convert.ToInt32(lastStockCount.FirstOrDefault().SCNumber) + 0000000001; defaultSCNumber = FillLeadingZeroes(SCNumber, 10); } var users = from d in db.MstUsers.OrderBy(d => d.FullName) where d.IsLocked == true select d; if (users.Any()) { Data.TrnStockCount newStockCount = new Data.TrnStockCount { BranchId = currentBranchId, SCNumber = defaultSCNumber, SCDate = DateTime.Today, Particulars = "NA", PreparedById = currentUserId, CheckedById = currentUserId, ApprovedById = currentUserId, IsPrinted = false, IsLocked = false, CreatedById = currentUserId, CreatedDateTime = DateTime.Now, UpdatedById = currentUserId, UpdatedDateTime = DateTime.Now }; db.TrnStockCounts.InsertOnSubmit(newStockCount); db.SubmitChanges(); String newObject = at.GetObjectString(newStockCount); at.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, "NA", newObject); return(Request.CreateResponse(HttpStatusCode.OK, newStockCount.Id)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "No user found. Please setup more users for all transactions.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add stock count.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this stock count page.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in.")); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }
public int Post(Models.TrnStockCount stockCount) { try { var isLocked = 1; var identityUserId = User.Identity.GetUserId(); var mstUserId = (from d in db.MstUsers where "" + d.Id == identityUserId select d.Id).SingleOrDefault(); var date = DateTime.Now; Data.TrnStockCount newStockCount = new Data.TrnStockCount(); newStockCount.PeriodId = stockCount.PeriodId; newStockCount.StockCountDate = Convert.ToDateTime(stockCount.StockCountDate); newStockCount.StockCountNumber = stockCount.StockCountNumber; newStockCount.Remarks = stockCount.Remarks; newStockCount.PreparedBy = stockCount.PreparedBy; newStockCount.CheckedBy = stockCount.CheckedBy; newStockCount.ApprovedBy = stockCount.ApprovedBy; newStockCount.IsLocked = isLocked; newStockCount.EntryUserId = mstUserId; newStockCount.EntryDateTime = date; newStockCount.UpdateUserId = mstUserId; newStockCount.UpdateDateTime = date; db.TrnStockCounts.InsertOnSubmit(newStockCount); db.SubmitChanges(); return newStockCount.Id; } catch { return 0; } }
public Int32 insertStockCount(Models.TrnStockCount stockCount) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); var lastSCNumber = from d in db.TrnStockCounts.OrderByDescending(d => d.Id) select d; var SCNumberResult = "0000000001"; if (lastSCNumber.Any()) { var SCNumber = Convert.ToInt32(lastSCNumber.FirstOrDefault().SCNumber) + 0000000001; SCNumberResult = zeroFill(SCNumber, 10); } Data.TrnStockCount newStockCount = new Data.TrnStockCount(); newStockCount.BranchId = currentBranchId(); newStockCount.SCNumber = SCNumberResult; newStockCount.SCDate = DateTime.Today; newStockCount.Particulars = "NA"; newStockCount.PreparedById = userId; newStockCount.CheckedById = userId; newStockCount.ApprovedById = userId; newStockCount.IsLocked = false; newStockCount.CreatedById = userId; newStockCount.CreatedDateTime = DateTime.Now; newStockCount.UpdatedById = userId; newStockCount.UpdatedDateTime = DateTime.Now; db.TrnStockCounts.InsertOnSubmit(newStockCount); db.SubmitChanges(); return newStockCount.Id; } catch { return 0; } }