public int Update(Data.Models.IndentDetail IndentDetail, string itemDescription) { Data.Models.IndentDetail existingID = _IndentDetailRepository.Table.FirstOrDefault(w => w.Id == IndentDetail.Id); if (existingID != null) { var existingItem = this._itemRepository.Table.FirstOrDefault(f => f.Id == existingID.ItemId); if (existingItem != null) { existingItem.Description = itemDescription; } existingID.PreferredVendorId = IndentDetail.PreferredVendorId; existingID.Make = IndentDetail.Make; existingID.EstimatePrice = IndentDetail.EstimatePrice; existingID.Currency = IndentDetail.Currency; existingID.ExchangeRate = IndentDetail.ExchangeRate; existingID.QtyNeeded = IndentDetail.QtyNeeded; existingID.RequiredByDate = IndentDetail.RequiredByDate; existingID.StatusId = IndentDetail.StatusId; existingID.JobDescription = IndentDetail.JobDescription; existingID.UnitOfMeasure = IndentDetail.UnitOfMeasure; _IndentDetailRepository.Update(existingID); return(existingID.Id); } else { return(0); } }
public int UpdateRejectTask(Data.Models.IndentDetail IndentDetail, DateTime rejectedDate, int userId, DateTime approvedDate) { Data.Models.IndentDetail existingID = _IndentDetailRepository.Table.FirstOrDefault(w => w.Id == IndentDetail.Id); if (existingID != null) { existingID.Rejectedon = rejectedDate; existingID.RejectedBy = userId; existingID.StatusId = IndentDetail.StatusId; existingID.ApprovedBy = null; existingID.ApprovedOn = null; _IndentDetailRepository.Update(existingID); return(existingID.Id); } else { return(0); } }
public int Add(Data.Models.IndentDetail IndentDetail, string itemDescription) { var existingItem = this._itemRepository.Table.FirstOrDefault(f => f.Id == IndentDetail.ItemId); if (existingItem != null) { existingItem.Description = itemDescription; } var existingIndent = this._IndentsRepository.Table.FirstOrDefault(f => f.Id == IndentDetail.IndentId); if (existingIndent.RequisitionType == "JR") { IndentDetail.ItemId = null; } _IndentDetailRepository.Insert(IndentDetail); return(IndentDetail.Id); }
public int UpdateIssuedTask(Data.Models.IndentDetail IndentDetail, DateTime issuedDate, int userId) { Data.Models.IndentDetail existingID = _IndentDetailRepository.Table.FirstOrDefault(w => w.Id == IndentDetail.Id); if (existingID != null) { existingID.IssuedOn = issuedDate; existingID.IssuedBy = userId; existingID.IssuedQty = IndentDetail.IssuedQty; existingID.FinalPrice = IndentDetail.FinalPrice; existingID.StatusId = IndentDetail.StatusId; _IndentDetailRepository.Update(existingID); return(existingID.Id); } else { return(0); } }
public int UpdatePoTask(Data.Models.IndentDetail IndentDetail) { Data.Models.IndentDetail existingID = _IndentDetailRepository.Table.FirstOrDefault(w => w.Id == IndentDetail.Id); if (existingID != null) { existingID.PoNo = IndentDetail.PoNo; existingID.PoDate = IndentDetail.PoDate; existingID.DeliveryDate = IndentDetail.DeliveryDate; existingID.StatusId = IndentDetail.StatusId; existingID.PoAmount = IndentDetail.PoAmount; _IndentDetailRepository.Update(existingID); return(existingID.Id); } else { return(0); } }
public JsonNetResult SaveIndentDetail(IndentDetail IndentDetail, string itemDescription) { var result = new JsonResponse(); try { result.Status = JsonResponseStatus.Success; IndentDetail IDobj = new Data.Models.IndentDetail(); if (IndentDetail.Id == 0) { if (IndentDetail.StatusId > 1) { result.Status = JsonResponseStatus.Warning; result.Message = "Status should be 'New' for new request. Data not saved."; } else { IndentDetail.Id = this._IndentDetailServices.Add(IndentDetail, itemDescription); result.Data = new { Id = IndentDetail.Id }; } } else { result.Data = new { Id = IndentDetail.Id }; if (IndentDetail.StatusId == 2) //Approved { if (HttpContext.User.IsInRole("Lavel2")) { int userId = HttpContext.User.Identity.GetUserId <int>(); DateTime approvedDate = DateTime.UtcNow; DateTime rejectedDate = DateTime.UtcNow; this._IndentDetailServices.UpdateApproveTask(IndentDetail, approvedDate, userId, rejectedDate); } else { result.Status = JsonResponseStatus.Warning; result.Message = "You are not authorized to do this action. Data not saved."; } } if (IndentDetail.StatusId == 3) //Rejected { if (HttpContext.User.IsInRole("Lavel2")) { int userId = HttpContext.User.Identity.GetUserId <int>(); DateTime rejectedDate = DateTime.UtcNow; DateTime approvedDate = DateTime.UtcNow; this._IndentDetailServices.UpdateRejectTask(IndentDetail, rejectedDate, userId, approvedDate); } else { result.Status = JsonResponseStatus.Warning; result.Message = "You are not authorized to do this action. Data not saved."; } } if (IndentDetail.StatusId == 4) //PO { var existing = this._IndentDetailServices.GetForId(IndentDetail.Id); int oldStatusId = Convert.ToInt32(existing.StatusId); // Get this from db. if (oldStatusId == 2) { if (IndentDetail.PoDate == null) { result.Status = JsonResponseStatus.Warning; result.Message = "'Please insert PO Date."; } else if (IndentDetail.DeliveryDate == null) { result.Status = JsonResponseStatus.Warning; result.Message = "Please insert delivery Date."; } else if (IndentDetail.PoNo == null) { result.Status = JsonResponseStatus.Warning; result.Message = "Please insert PO no."; } else if (IndentDetail.PoAmount <= 0) { result.Status = JsonResponseStatus.Warning; result.Message = "Please insert PO Amount greater than zero."; } else { this._IndentDetailServices.UpdatePoTask(IndentDetail); } } else if (oldStatusId == 3) { result.Status = JsonResponseStatus.Warning; result.Message = "This item is already rejected. You can not change it's status."; } else if (oldStatusId == 4) { result.Status = JsonResponseStatus.Warning; result.Message = "PO already placed. Data not saved."; } else if (oldStatusId == 5) { result.Status = JsonResponseStatus.Warning; result.Message = "This item is already received. You can not change it's status."; } else { result.Status = JsonResponseStatus.Warning; result.Message = "This item is not approved yet. Data not saved."; } } if (IndentDetail.StatusId == 5) //Issued { var existing = this._IndentDetailServices.GetForId(IndentDetail.Id); int oldStatusId = Convert.ToInt32(existing.StatusId); // Get this from db. int userId = HttpContext.User.Identity.GetUserId <int>(); DateTime issuedDate = DateTime.UtcNow; if (oldStatusId == 2 || oldStatusId == 4) { if (IndentDetail.IssuedQty == null) { result.Status = JsonResponseStatus.Warning; result.Message = "Issued quantity must be greater than zero(0)."; } else if (IndentDetail.PoAmount == 0) { result.Status = JsonResponseStatus.Warning; result.Message = "Please insert PO Amount."; } else { this._IndentDetailServices.UpdateIssuedTask(IndentDetail, issuedDate, userId); } } else if (oldStatusId == 3) { result.Status = JsonResponseStatus.Warning; result.Message = "This item is already rejected. You can not change it's status."; } else if (oldStatusId == 5) { result.Status = JsonResponseStatus.Warning; result.Message = "This item already received. Can not issue again."; } else { result.Status = JsonResponseStatus.Warning; result.Message = "This item is not approved yet. Data not saved."; } } if (IndentDetail.StatusId == 1) //New { var existing = this._IndentDetailServices.GetForId(IndentDetail.Id); int oldStatusId = Convert.ToInt32(existing.StatusId); // Get this from db. if (oldStatusId == 5) { result.Status = JsonResponseStatus.Warning; result.Message = "This item is already received. You can not change it's status."; } else if (oldStatusId == 4) { result.Status = JsonResponseStatus.Warning; result.Message = "This item is already PO. You can not change it's status."; } else if (oldStatusId == 3) { result.Status = JsonResponseStatus.Warning; result.Message = "This item is already rejected. You can not change it's status."; } else if (oldStatusId == 2) { result.Status = JsonResponseStatus.Warning; result.Message = "This item is already approved. You can not change it's status."; } else { this._IndentDetailServices.Update(IndentDetail, itemDescription); } } } } catch (Exception ex) { result.Status = JsonResponseStatus.Error; result.Message = ex.Message + ex.InnerException ?? ex.InnerException.Message; } return(JsonNet(result, JsonRequestBehavior.AllowGet)); }