public HttpResponseMessage unlockStockIn(String id, Models.TrnStockIn stockIn) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); var stockIns = from d in db.TrnStockIns where d.Id == Convert.ToInt32(id) select d; if (stockIns.Any()) { var updateStockIn = stockIns.FirstOrDefault(); updateStockIn.IsLocked = false; updateStockIn.UpdatedById = userId; updateStockIn.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); inventory.deleteINInventory(Convert.ToInt32(id)); journal.deleteINJournal(Convert.ToInt32(id)); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } catch { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public Int32 insertStockIn(Models.TrnStockIn stockIn) { try { var lastINNumber = from d in db.TrnStockIns.OrderByDescending(d => d.Id) where d.BranchId == currentBranchId() select d; var INNumberResult = "0000000001"; if (lastINNumber.Any()) { var INNumber = Convert.ToInt32(lastINNumber.FirstOrDefault().INNumber) + 0000000001; INNumberResult = zeroFill(INNumber, 10); } var users = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d).FirstOrDefault(); Data.TrnStockIn newStockIn = new Data.TrnStockIn(); newStockIn.BranchId = currentBranchId(); newStockIn.INNumber = INNumberResult; newStockIn.INDate = DateTime.Today; newStockIn.AccountId = users.IncomeAccountId; newStockIn.ArticleId = (from d in db.MstArticles where d.ArticleTypeId == 6 select d.Id).FirstOrDefault(); newStockIn.Particulars = "NA"; newStockIn.ManualINNumber = "NA"; newStockIn.IsProduced = false; newStockIn.PreparedById = users.Id; newStockIn.CheckedById = users.Id; newStockIn.ApprovedById = users.Id; newStockIn.IsLocked = false; newStockIn.CreatedById = users.Id; newStockIn.CreatedDateTime = DateTime.Now; newStockIn.UpdatedById = users.Id; newStockIn.UpdatedDateTime = DateTime.Now; db.TrnStockIns.InsertOnSubmit(newStockIn); db.SubmitChanges(); return(newStockIn.Id); } catch (Exception e) { Debug.WriteLine(e); return(0); } }
public HttpResponseMessage updateStockIn(String id, Models.TrnStockIn stockIn) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); var stockIns = from d in db.TrnStockIns where d.Id == Convert.ToInt32(id) select d; if (stockIns.Any()) { var updateStockIn = stockIns.FirstOrDefault(); updateStockIn.BranchId = stockIn.BranchId; updateStockIn.INNumber = stockIn.INNumber; updateStockIn.INDate = Convert.ToDateTime(stockIn.INDate); updateStockIn.AccountId = stockIn.AccountId; updateStockIn.ArticleId = stockIn.ArticleId; updateStockIn.Particulars = stockIn.Particulars; updateStockIn.ManualINNumber = stockIn.ManualINNumber; updateStockIn.IsProduced = stockIn.IsProduced; updateStockIn.PreparedById = stockIn.PreparedById; updateStockIn.CheckedById = stockIn.CheckedById; updateStockIn.ApprovedById = stockIn.ApprovedById; updateStockIn.IsLocked = true; updateStockIn.UpdatedById = userId; updateStockIn.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); inventory.insertINInventory(Convert.ToInt32(id), stockIn.IsProduced); journal.insertINJournal(Convert.ToInt32(id)); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } catch { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }