public IHttpActionResult DeleteMemoJobCard(int memoJobCardID, int componentID, int memoComponentID, int memoQuantity, string userID, string userName) { using (PowerAppsCMSEntities db = new PowerAppsCMSEntities()) { Guid guidUserID = Guid.Parse(userID.Replace(" ", string.Empty)); DateTime now = DateTime.Now; MemoJobCard selectedMemoJobCard = db.MemoJobCards.Find(memoJobCardID); db.MemoJobCards.Remove(selectedMemoJobCard); if (db.SaveChanges() > 0) { MemoComponent selectedMemoComponent = db.MemoComponents.Where(x => x.ID == memoComponentID).SingleOrDefault(); bool isEqualValue = IsEqual(componentID, memoComponentID, memoQuantity); if (isEqualValue == false && selectedMemoComponent.Status == (int)MemoStatus.Complete) { selectedMemoComponent.Status = (int)MemoStatus.OnProcess; selectedMemoComponent.LastModifiedBy = userName; selectedMemoComponent.LastModified = now; db.SaveChanges(); } int countListMemoJobCards = db.MemoJobCards.Where(x => x.MemoComponentID == memoComponentID).Count(); if (countListMemoJobCards == 0) { selectedMemoComponent.Status = (int)MemoStatus.NotStarted; selectedMemoComponent.LastModifiedBy = userName; selectedMemoComponent.LastModified = now; db.SaveChanges(); } } return(Ok(HttpStatusCode.OK)); } }
public IHttpActionResult PostMemoJobCard(int componentID, int memoComponentID, int PBProcessID, int quantity, int memoQuantity, string userID, string userName) { using (PowerAppsCMSEntities db = new PowerAppsCMSEntities()) { Guid guidUserID = Guid.Parse(userID.Replace(" ", string.Empty)); DateTime now = DateTime.Now; MemoJobCard memoJobCard = new MemoJobCard(); memoJobCard.MemoComponentID = memoComponentID; memoJobCard.MaterialPreparationProcessID = PBProcessID; memoJobCard.Quantity = quantity; memoJobCard.UserID = guidUserID; memoJobCard.Created = memoJobCard.LastModified = now; memoJobCard.CreatedBy = memoJobCard.LastModifiedBy = userName; db.MemoJobCards.Add(memoJobCard); if (db.SaveChanges() > 0) { MemoComponent selectedMemoComponent = db.MemoComponents.Where(x => x.ID == memoComponentID).SingleOrDefault(); if (selectedMemoComponent.Status == (int)MemoStatus.NotStarted) { selectedMemoComponent.Status = (int)MemoStatus.OnProcess; selectedMemoComponent.LastModifiedBy = userName; selectedMemoComponent.LastModified = now; db.SaveChanges(); } bool isEqualValue = IsEqual(componentID, memoComponentID, memoQuantity); if (isEqualValue == true) { selectedMemoComponent.Status = (int)MemoStatus.Complete; selectedMemoComponent.LastModifiedBy = userName; selectedMemoComponent.LastModified = now; db.SaveChanges(); } } return(Ok(HttpStatusCode.OK)); } }