public static ResultResponse Settlement(SouvenirRequestViewModel entity, List <SouvenirItemViewModel> entityItem) { ResultResponse result = new ResultResponse(); try { using (var db = new MarComContext()) { T_Souvenir so = db.T_Souvenir.Where(sou => sou.Id == entity.Id).FirstOrDefault(); if (so != null) { so.Status = 4; so.Settlement_By = entity.Settlement_By; so.Settlement_Date = DateTime.Now; foreach (var item in entityItem) { T_Souvenir_Item si = db.T_Souvenir_Item.Where(s => s.Id == item.Id).FirstOrDefault(); si.Qty_Settlement = item.Qty_Settlement; } db.SaveChanges(); result.Message = "Data Updated !! Transaction Souvenir Request with code" + entity.Code + "has been Settled By Requester"; } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public static ResultResponse Update(SouvenirRequestViewModel entity, List <SouvenirItemViewModel> entityitem) { ResultResponse result = new ResultResponse(); try { using (var db = new MarComContext()) { if (entity.Id == 0) { T_Souvenir t_Souv = new T_Souvenir(); t_Souv.Code = entity.Code; t_Souv.Type = "Additional"; t_Souv.T_Event_Id = entity.T_Event_Id; t_Souv.Request_By = entity.Request_By; t_Souv.Request_Date = entity.Request_Date; t_Souv.Request_Due_Date = entity.Request_Due_Date; t_Souv.Note = entity.Note; t_Souv.Status = 1; t_Souv.Create_By = entity.Create_By; t_Souv.Create_Date = DateTime.Now; db.T_Souvenir.Add(t_Souv); db.SaveChanges(); foreach (var item in entityitem) { T_Souvenir_Item t_SouvItem = new T_Souvenir_Item(); t_SouvItem.T_Souvenir_Id = t_Souv.Id; t_SouvItem.M_Souvenir_Id = item.M_Souvenir_Id; t_SouvItem.Qty = item.Qty; t_SouvItem.Note = item.Note; t_SouvItem.Is_Delete = item.Is_Delete; t_SouvItem.Create_By = entity.Create_By; t_SouvItem.Create_Date = DateTime.Now; db.T_Souvenir_Item.Add(t_SouvItem); db.SaveChanges(); } result.Message = "Data Saved ! Transaction Souvenir Request has been add with code " + entity.Code; } else { T_Souvenir t_Souv = db.T_Souvenir.Where(ts => ts.Id == entity.Id).FirstOrDefault(); if (t_Souv != null) { t_Souv.Code = entity.Code; t_Souv.T_Event_Id = entity.T_Event_Id; t_Souv.Request_By = entity.Request_By; t_Souv.Request_Date = entity.Request_Date; t_Souv.Request_Due_Date = entity.Request_Due_Date; t_Souv.Note = entity.Note; t_Souv.Status = 1; t_Souv.Update_By = entity.Update_By; t_Souv.Update_Date = DateTime.Now; foreach (var item in entityitem) { T_Souvenir_Item t_SouvItem = new T_Souvenir_Item(); t_SouvItem.T_Souvenir_Id = entity.Id; t_SouvItem.M_Souvenir_Id = item.M_Souvenir_Id; t_SouvItem.Qty = item.Qty; t_SouvItem.Note = item.Note; t_SouvItem.Is_Delete = item.Is_Delete; if (item.Id == 0) { t_SouvItem.Create_By = entity.Update_By; t_SouvItem.Create_Date = DateTime.Now; } else { t_SouvItem.Create_By = item.Create_By; t_SouvItem.Create_Date = item.Create_Date; t_SouvItem.Update_By = entity.Update_By; t_SouvItem.Update_Date = DateTime.Now; } db.T_Souvenir_Item.Add(t_SouvItem); } db.SaveChanges(); } result.Message = "Data Update ! Transaction Souvenir Request with code " + entity.Code + " has been update"; } } } catch (Exception ex) { throw; result.Success = false; result.Message = ex.Message; } return(result); }
public static ResultResponse Update(SouvenirStockViewModel entity, List <SouvenirItemViewModel> entityitem) { ResultResponse result = new ResultResponse(); try { using (var db = new MarComContext()) { if (entity.Id == 0) { T_Souvenir tsouv = new T_Souvenir(); tsouv.Code = entity.Code; tsouv.Type = "Additional"; tsouv.Received_By = entity.Received_By; tsouv.Received_Date = entity.Received_Date; tsouv.Note = entity.Note; tsouv.Create_By = entity.Create_By; tsouv.Create_Date = DateTime.Now; db.T_Souvenir.Add(tsouv); foreach (var item in entityitem) { T_Souvenir_Item tsouvItem = new T_Souvenir_Item(); tsouvItem.T_Souvenir_Id = entity.Id; tsouvItem.M_Souvenir_Id = item.M_Souvenir_Id; tsouvItem.Qty = item.Qty; tsouvItem.Note = item.Note; tsouvItem.Is_Delete = item.Is_Delete; tsouvItem.Create_By = entity.Create_By; tsouvItem.Create_Date = DateTime.Now; db.T_Souvenir_Item.Add(tsouvItem); } db.SaveChanges(); } else { T_Souvenir tsouv = db.T_Souvenir.Where(ts => ts.Id == entity.Id).FirstOrDefault(); if (tsouv != null) { tsouv.Code = entity.Code; tsouv.Type = "Additional"; tsouv.Received_By = entity.Received_By; tsouv.Received_Date = entity.Received_Date; tsouv.Note = entity.Note; tsouv.Update_By = entity.Update_By; tsouv.Update_Date = DateTime.Now; foreach (var item in entityitem) { T_Souvenir_Item tsouvItem = new T_Souvenir_Item(); tsouvItem.T_Souvenir_Id = entity.Id; tsouvItem.M_Souvenir_Id = item.M_Souvenir_Id; tsouvItem.Qty = item.Qty; tsouvItem.Note = item.Note; tsouvItem.Is_Delete = item.Is_Delete; if (item.Id == 0) { tsouvItem.Create_By = entity.Update_By; tsouvItem.Create_Date = DateTime.Now; } else { tsouvItem.Update_By = entity.Update_By; tsouvItem.Update_Date = DateTime.Now; } db.T_Souvenir_Item.Add(tsouvItem); } db.SaveChanges(); } } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }