// GET: api/Invoices public bool Delete(int id) { using (var db = new OcphDbContext()) { var trans = db.BeginTransaction(); try { var IsDeletedDetails = db.InvoiceDetails.Delete(O => O.InvoiceId == id); if (IsDeletedDetails) { var IsDelete = db.Invoices.Delete(O => O.Id == id); if (IsDelete) { trans.Commit(); } } throw new SystemException(MessageCollection.Message(MessageType.DeleteFail)); } catch (Exception) { trans.Rollback(); return(false); } } }
public manifestoutgoing InsertAndGetItem(manifestoutgoing t) { using (var db = new OcphDbContext()) { var transaction = db.BeginTransaction(); try { t.Code = Helpers.GenerateOutgoingCode(); var date = DateTime.Now; t.CreatedDate = date; t.UpdateDate = date; var manifestId = db.Outgoing.InsertAndGetLastID(t); if (manifestId > 0) { foreach (var item in t.PackingList) { item.ManifestID = manifestId; item.Id = db.PackingLists.InsertAndGetLastID(item); if (item.Id <= 0) { throw new SystemException("Error"); } } transaction.Commit(); return(t); } throw new SystemException("Error"); } catch (Exception ex) { transaction.Rollback(); throw new SystemException(ex.Message); } } }
public Task <bool> DeletePhoto(IPhoto result) { string fullFileName = string.Format("{0}{1}.{2}", AppPath, result.File, result.Ext); using (var db = new OcphDbContext()) { var trans = db.BeginTransaction(); try { var isDeleted = db.Photos.Delete(O => O.Id == result.Id); if (isDeleted) { File.Delete(fullFileName); trans.Commit(); return(Task.FromResult(isDeleted)); } else { throw new SystemException("Photo Tidak Terhapus"); } } catch (Exception ex) { trans.Rollback(); throw new SystemException(ex.Message); } } }
public penjualan InsertAndGetItem(penjualan value) { var date = DateTime.Now; value.ChangeDate = date; value.UpdateDate = date; using (var db = new OcphDbContext()) { if (value.Details != null && value.Details.Count > 0) { var tr = db.BeginTransaction(); try { if (value.STT == 0) { value.STT = NewSTT(); } value.Id = db.Penjualans.InsertAndGetLastID(value); if (value.Id > 0) { foreach (var item in value.Details) { item.PenjualanId = value.Id; item.Id = db.Collies.InsertAndGetLastID(item); } tr.Commit(); } else { throw new SystemException(MessageCollection.Message(MessageType.SaveFail)); } } catch (Exception ex) { tr.Rollback(); throw new SystemException(ex.Message); } } else { throw new SystemException("Item Berang Belum ada"); } } return(value); }
public invoice InsertAndGetItem(invoice t) { using (var db = new OcphDbContext()) { var trans = db.BeginTransaction(); try { var lastnumber = db.Invoices.GetLastItem(); if (lastnumber == null) { t.Number = 1; } else { t.Number = lastnumber.Number + 1; } t.Id = db.Invoices.InsertAndGetLastID(t); if (t.Id <= 0) { throw new SystemException(MessageCollection.Message(MessageType.SaveFail)); } foreach (var item in t.Details) { item.InvoiceId = t.Id; item.Id = db.InvoiceDetails.InsertAndGetLastID(item); if (item.Id <= 0) { throw new SystemException(MessageCollection.Message(MessageType.SaveFail)); } } trans.Commit(); return(t); } catch (Exception ex) { trans.Rollback(); throw new SystemException(ex.Message); } } }
public penjualan Update(int id, penjualan value) { var date = DateTime.Now; value.UpdateDate = date; using (var db = new OcphDbContext()) { if (value.Details != null && value.Details.Count > 0) { var tr = db.BeginTransaction(); try { var dbcolies = db.Collies.Where(O => O.PenjualanId == value.Id).ToList(); foreach (var item in value.Details) { if (item.Id > 0) { var saved = db.Collies.Update(O => new { O.CollyNumber, O.Hight, O.Long, O.Weight, O.Wide, O.TypeOfWeight }, item, O => O.Id == item.Id); if (!saved) { throw new SystemException(MessageCollection.Message(MessageType.UpdateFaild)); } } else { item.Id = db.Collies.InsertAndGetLastID(item); if (item.Id <= 0) { throw new SystemException(MessageCollection.Message(MessageType.UpdateFaild)); } } } foreach (var item in dbcolies) { var ondata = value.Details.Find(O => O.Id == item.Id); if (ondata == null) { db.Collies.Delete(O => O.Id == item.Id); } } var savedParent = db.Penjualans.Update(O => new { O.UpdateDate, O.From, O.To, O.Content, O.CustomerIdIsPay, O.DoNumber, O.Etc, O.IsPaid, O.Note, O.PackingCosts, O.PayType, O.PortType, O.Price, O.ReciverID, O.ShiperID, O.STT, O.Tax, O.TypeOfWeight, O.UserID, O.ChangeDate }, value, O => O.Id == value.Id); if (!savedParent) { throw new SystemException(MessageCollection.Message(MessageType.UpdateFaild)); } tr.Commit(); return(value); } catch (Exception ex) { tr.Rollback(); throw new SystemException(ex.Message); } } else { throw new SystemException("Item Berang Belum ada"); } } }