// PUT: api/City/5 public city Put(int id, city value) { using (var db = new OcphDbContext()) { if (db.Cities.Update(O => new { O.CityCode, O.CityName, O.Province, O.Regency }, value, O => O.Id == value.Id)) { return(value); } else { return(default(city)); } } }
public ship UpdateAndGetItem(ship t) { using (var db = new OcphDbContext()) { if (db.Ships.Update(O => new { O.Description, O.Name }, t, O => O.Id == t.Id)) { return(t); } else { throw new SystemException(MessageCollection.Message(MessageType.UpdateFaild)); } } }
public bool IsSended(int Id) { using (var db = new OcphDbContext()) { var result = db.Collies.Where(O => O.PenjualanId == Id && O.IsSended == true); if (result.Count() > 0) { return(true); } else { return(false); } } }
public Task <colly> Get(int id) { using (var db = new OcphDbContext()) { var result = db.Collies.Where(O => O.Id == id).FirstOrDefault(); if (result != null) { return(Task.FromResult(result)); } else { throw new SystemException("Data Tidak Ditemukan"); } } }
internal static string GetUserId(string name) { using (var db = new OcphDbContext()) { var u = db.Users.Where(O => O.UserName == name).FirstOrDefault(); if (u != null) { return(u.Id); } else { throw new SystemException("Not Found !"); } } }
// POST: api/City public city Post(city value) { using (var db = new OcphDbContext()) { value.Id = db.Cities.InsertAndGetLastID(value); if (value.Id <= 0) { throw new SystemException(MessageCollection.Message(MessageType.SaveFail)); } else { return(value); } } }
public invoice UpdateInvoiceStatusAction(int Id, invoice t) { using (var db = new OcphDbContext()) { var result = db.Invoices.Update(O => new { O.InvoicePayType, O.InvoiceStatus, O.PaidDate }, t, O => O.Id == Id); if (result) { return(t); } else { throw new SystemException("Data Tidak Tersimpan"); } } }
public invoice UpdateDeliveryDataAction(int Id, invoice t) { using (var db = new OcphDbContext()) { var res = db.Invoices.Update(O => new { O.DeliveryDate, O.ReciveDate, O.ReciverBy, O.IsDelivery }, t, O => O.Id == Id); if (res) { return(t); } else { throw new SystemException("Data Tidak Tersimpan"); } } }
public manifestoutgoing UpdateDestination(manifestoutgoing manifest) { using (var db = new OcphDbContext()) { var isUpdated = db.Outgoing.Update(O => new { O.OnDestinationPort }, manifest, O => O.Id == manifest.Id); if (isUpdated) { return(manifest); } else { throw new SystemException("Data Tidak tersimpan"); } } }
private bool CheckPortAccess(penjualan value) { using (var db = new OcphDbContext()) { var ports = db.Ports.Where(O => O.CityID == value.To && O.PortType == value.PortType).FirstOrDefault(); if (ports != null) { return(true); } else { return(false); } } }
internal static int GenerateOutgoingCode() { using (var db = new OcphDbContext()) { var u = db.Outgoing.GetLastItem(); if (u != null) { return(u.Code + 1); } else { return(1); } } }
public ship InsertAndGetItem(ship t) { using (var db = new OcphDbContext()) { t.Id = db.Ships.InsertAndGetLastID(t); if (t.Id > 0) { return(t); } else { throw new SystemException(MessageCollection.Message(MessageType.SaveFail)); } } }
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 deliverystatus UpdateDeliveryStatus(deliverystatus obj) { using (var db = new OcphDbContext()) { var isUpdated = db.DeliveryStatusses.Update(O => new { O.Description, O.IsSignIn, O.Phone, O.ReciveDate, O.ReciveName, O.UserID }, obj, O => O.Id == obj.Id && O.PenjualanId == obj.PenjualanId); if (isUpdated) { return(obj); } else { throw new SystemException("Tidak Tersimpan"); } } }
public IEnumerable <invoice> Get(DateTime start, DateTime end) { using (var db = new OcphDbContext()) { var cmd = db.CreateCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "GetAllInvoice"; cmd.Parameters.Add(new MySqlParameter("StartDate", start)); cmd.Parameters.Add(new MySqlParameter("EndDate", end)); var reader = cmd.ExecuteReader(); var result = MappingProperties <invoice> .MappingTable(reader); return(result); } }
// POST: api/Agents public agent Post(agent value) { using (var db = new OcphDbContext()) { value.Id = db.Agents.InsertAndGetLastID(value); if (value.Id > 0) { return(value); } else { throw new SystemException(MessageCollection.Message(MessageType.SaveFail)); } } }
public Task <double> GetPenjualanBulan(int month, int year) { using (var db = new OcphDbContext()) { var result = db.Penjualans.Where(O => O.ChangeDate.Month == month && O.ChangeDate.Year == year); foreach (var item in result) { item.Details = db.Collies.Where(O => O.PenjualanId == item.Id).ToList(); item.Shiper = db.Customers.Where(O => O.Id == item.ShiperID).FirstOrDefault(); item.Reciver = db.Customers.Where(O => O.Id == item.ReciverID).FirstOrDefault(); item.DeliveryStatus = db.DeliveryStatusses.Where(O => O.PenjualanId == item.Id).FirstOrDefault(); } return(Task.FromResult(result.Sum(O => O.Total))); } }
public List <IPhoto> GetPhotoByPenjualanId(int Id) { using (var db = new OcphDbContext()) { var data = from a in db.Photos.Where(O => O.PenjualanId == Id) select new Photo { Ext = a.Ext, File = a.File, Id = a.Id, Path = a.Path, PenjualanId = a.PenjualanId }; List <IPhoto> list = new List <IPhoto>(); foreach (var item in data) { list.Add(item); } return(list); } }
public Task <List <invoice> > GetInvoiceNotYetPaid() { using (var db = new OcphDbContext()) { var sp = string.Format("InvoiceNotYetPaid"); var cmd = db.CreateCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = sp; var dr = cmd.ExecuteReader(); var ent = new EntityInfo(typeof(ModelsShared.Models.invoice)); var list = new MappingColumn(ent).MappingWithoutInclud <invoice>(dr); dr.Close(); return(Task.FromResult(list)); } }
public IPhoto GetPhotoById(int id) { using (var db = new OcphDbContext()) { var item = db.Photos.Where(O => O.Id == id).FirstOrDefault(); if (item != null) { return(new Photo { Ext = item.Ext, File = item.File, Id = item.Id, PenjualanId = item.PenjualanId, Path = item.Path }); } else { throw new SystemException("Photo Tidak Ditemukan"); } } }
public Task <List <invoice> > GetInvoiceJatuhTempo() { using (var db = new OcphDbContext()) { var sp = string.Format("InvoiceJatuhTempo"); var cmd = db.CreateCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = sp; cmd.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("Tanggal", DateTime.Now)); var dr = cmd.ExecuteReader(); var ent = new EntityInfo(typeof(ModelsShared.Models.invoice)); var list = new MappingColumn(ent).MappingWithoutInclud <invoice>(dr); dr.Close(); return(Task.FromResult(list)); } }
public IEnumerable <penjualan> GetPenjualanNotPaid(int Id) { using (var db = new OcphDbContext()) { PayType status = PayType.Credit; var result = db.Penjualans.Where(O => O.PayType == status && O.CustomerIdIsPay == Id && O.IsPaid == false); foreach (var item in result) { item.Shiper = db.Customers.Where(o => o.Id == item.ShiperID).FirstOrDefault(); item.Reciver = db.Customers.Where(o => o.Id == item.ReciverID).FirstOrDefault(); item.Details = db.Collies.Where(o => o.PenjualanId == item.Id).ToList(); item.DeliveryStatus = db.DeliveryStatusses.Where(O => O.PenjualanId == item.Id).FirstOrDefault(); } return(result); } }
public IEnumerable <ModelsShared.Models.port> Get() { using (var db = new OcphDbContext()) { var result = from a in db.Ports.Select() join b in db.Cities.Select(O => new { O.Id, O.CityName }) on a.CityID equals b.Id select new ModelsShared.Models.port { CityID = a.CityID, CityName = b.CityName, Code = a.Code, Name = a.Name, Id = a.Id, PortType = a.PortType }; return(result); } }
public userprofile Put(int profileid, userprofile value, string name) { using (var db = new OcphDbContext()) { string userid = Helpers.GetUserId(name); var isUpdated = db.UserProfiles.Update(O => new { O.FirstName, O.LastName, O.Address, O.Photo }, value, O => O.UserId == profileid); if (isUpdated) { return(value); } else { throw new SystemException(MessageCollection.Message(MessageType.UpdateFaild)); } } }
// POST: api/customers public customer Post(customer value) { using (var db = new OcphDbContext()) { value.Id = db.Customers.InsertAndGetLastID(value); if (value.Id <= 0) { throw new SystemException(MessageCollection.Message(MessageType.SaveFail)); } else { if (value.City == null) { value.City = db.Cities.Where(O => O.Id == value.CityID).FirstOrDefault(); } return(value); } } }
public deliverystatus UpdateDeliveryStatusBySTT(int id, deliverystatus obj) { try { using (var db = new OcphDbContext()) { var res = db.Penjualans.Where(O => O.STT == id).FirstOrDefault(); if (res != null) { obj.PenjualanId = res.Id; var deliveryId = db.DeliveryStatusses.Where(O => O.PenjualanId == res.Id).FirstOrDefault().Id; if (deliveryId <= 0) { throw new SystemException("Delivery Status Tidak Ditemukan"); } else { obj.Id = deliveryId; } var isUpdated = db.DeliveryStatusses.Update(O => new { O.Description, O.IsSignIn, O.Phone, O.ReciveDate, O.ReciveName, O.UserID }, obj, O => O.Id == obj.Id && O.PenjualanId == obj.PenjualanId); if (isUpdated) { return(obj); } else { throw new SystemException("Tidak Tersimpan"); } } else { throw new SystemException("STT Tidak Ditemukan"); } } } catch (Exception ex) { throw new SystemException(ex.Message); } }
public TracingModel GetPenjualan(int STT) { using (var db = new OcphDbContext()) { try { var cmd = db.CreateCommand(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "GetPenjualan"; cmd.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("STT", STT)); var reader = cmd.ExecuteReader(); var mapp = new MappingColumn(new EntityInfo(typeof(TracingModel))); var result = mapp.MappingWithoutInclud <TracingModel>(reader); reader.Close(); var tracing = result.FirstOrDefault(); if (result != null) { var packlists = db.PackingLists.Where(O => O.PenjualanId == tracing.Id).GroupBy(O => O.ManifestID).ToList(); tracing.Manifests = new List <manifestoutgoing>(); foreach (var item in packlists) { var manifest = db.Outgoing.Where(O => O.Id == item.Key).FirstOrDefault(); if (manifest != null) { tracing.Manifests.Add(manifest); } } return(tracing); } else { throw new SystemException(MessageCollection.Message(MessageType.NotFound)); } } catch (Exception ex) { throw new SystemException(ex.Message); } } }
public Prices SetPrices(Prices price) { if (price != null) { using (var db = new OcphDbContext()) { try { price.Id = db.Priceses.InsertAndGetLastID(price); if (price.Id > 0) { return(price); } else { throw new SystemException(MessageCollection.Message(MessageType.SaveFail)); } } catch (Exception ex) { try { if (ex.Message == "Data Sudah Ada") { var updated = db.Priceses.Update(O => new { O.Price }, price, O => O.ShiperId == price.ShiperId && O.From == price.From && O.To == price.To && O.PortType == price.PortType && O.PayType == price.PayType); if (updated) { return(price); } throw new SystemException(MessageCollection.Message(MessageType.UpdateFaild)); } } catch (Exception ex1) { throw new SystemException(ex1.Message); } } } } throw new SystemException("Pengirim atau Penerima tidak ditemukan"); }
public Task <invoice> GetInvoiceForPenjualanInfo(int Id) { invoice inv; using (var db = new OcphDbContext()) { var det = db.InvoiceDetails.Where(O => O.PenjualanId == Id).FirstOrDefault(); if (det != null) { inv = db.Invoices.Where(O => O.Id == det.InvoiceId).FirstOrDefault(); inv.Details.Add(det); return(Task.FromResult(inv)); } else { inv = null; return(Task.FromResult(inv)); } } }
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); } } }