示例#1
0
        // 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);
                }
            }
        }
示例#2
0
 public async Task <Port> Post(Port value)
 {
     db.Port.Add(value);
     if (await db.SaveChangesAsync() <= 0)
     {
         throw new SystemException(MessageCollection.Message(MessageType.SaveFail));
     }
     return(value);
 }
示例#3
0
 public async Task <Ships> InsertAndGetItem(Ships t)
 {
     db.Ships.Add(t);
     if (await db.SaveChangesAsync() > 0)
     {
         return(t);
     }
     else
     {
         throw new SystemException(MessageCollection.Message(MessageType.SaveFail));
     }
 }
示例#4
0
 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));
         }
     }
 }
示例#5
0
 // 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);
         }
     }
 }
示例#6
0
 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));
         }
     }
 }
示例#7
0
        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);
        }
示例#8
0
        // 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 async Task <Cityagentcanaccess> OnChangeItemTrue(Cityagentcanaccess obj)
 {
     try
     {
         db.Cityagentcanaccess.Add(obj);
         if (await db.SaveChangesAsync() <= 0)
         {
             throw new SystemException(MessageCollection.Message(MessageType.SaveFail));
         }
         return(obj);
     }
     catch (Exception ex)
     {
         throw new SystemException(ex.Message);
     }
 }
示例#10
0
        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));
                }
            }
        }
示例#11
0
        // POST: api/customers
        public async Task <Customer> Post(Customer value)
        {
            try
            {
                db.Customer.Add(value);
                var result = await db.SaveChangesAsync();

                if (result <= 0)
                {
                    throw new SystemException(MessageCollection.Message(MessageType.SaveFail));
                }
                return(value);
            }
            catch (Exception ex)
            {
                throw new SystemException(ex.Message);
            }
        }
示例#12
0
        // GET: api/Invoices
        public async Task <bool> Delete(int id)
        {
            try
            {
                var existsModel = db.Invoices.Where(x => x.Id == id).FirstOrDefault();
                db.Invoices.Remove(existsModel);
                var result = await db.SaveChangesAsync();

                if (result <= 0)
                {
                    throw new SystemException(MessageCollection.Message(MessageType.DeleteFail));
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#13
0
        // GET: api/Ships
        public async Task <bool> Delete(int id)
        {
            var existsShip = await GetById(id);

            if (existsShip == null)
            {
                throw new SystemException("Data Not Found !");
            }

            db.Ships.Remove(existsShip);
            if (await db.SaveChangesAsync() > 0)
            {
                return(true);
            }
            else
            {
                throw new SystemException(MessageCollection.Message(MessageType.UpdateFaild));
            }
        }
示例#14
0
 // 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);
         }
     }
 }
示例#15
0
        public async Task <Ships> UpdateAndGetItem(int id, Ships t)
        {
            var existsShip = await GetById(id);

            if (existsShip == null)
            {
                throw new SystemException("Data Not Found !");
            }

            db.Entry(existsShip).CurrentValues.SetValues(t);
            if (await db.SaveChangesAsync() > 0)
            {
                return(t);
            }
            else
            {
                throw new SystemException(MessageCollection.Message(MessageType.UpdateFaild));
            }
        }
示例#16
0
        public async Task <bool> Put(int id, Userprofile value)
        {
            try
            {
                var profile = db.Userprofile.Where(x => x.Id == id).FirstOrDefault();
                if (profile != null)
                {
                    db.Entry(profile).CurrentValues.SetValues(value);
                    await db.SaveChangesAsync();

                    return(true);
                }
                return(false);
            }
            catch
            {
                throw new SystemException(MessageCollection.Message(MessageType.UpdateFaild));
            }
        }
示例#17
0
        public async Task <Penjualan> InsertAndGetItem(Penjualan value)
        {
            var date = DateTime.Now;

            value.ChangeDate = date;
            value.UpdateDate = date;
            if (value.Colly != null && value.Colly.Count > 0)
            {
                try
                {
                    if (value.Stt == 0)
                    {
                        value.Stt = await NewSTT();
                    }

                    db.Set <Penjualan>().Add(value);
                    if (value.FromCityNavigation != null)
                    {
                        db.Entry(value.FromCityNavigation).State = EntityState.Unchanged;
                    }
                    if (value.ToCityNavigation != null)
                    {
                        db.Entry(value.ToCityNavigation).State = EntityState.Unchanged;
                    }
                    db.Entry(value.Shiper).State  = EntityState.Unchanged;
                    db.Entry(value.Reciver).State = EntityState.Unchanged;
                    if (await db.SaveChangesAsync() <= 0)
                    {
                        throw new SystemException(MessageCollection.Message(MessageType.SaveFail));
                    }
                }
                catch (Exception ex)
                {
                    throw new SystemException(ex.Message);
                }
            }
            else
            {
                throw new SystemException("Item Barang Belum ada");
            }
            return(value);
        }
示例#18
0
 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");
 }
示例#19
0
        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);
                }
            }
        }
示例#20
0
        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);
                }
            }
        }
示例#21
0
 public CityAgentCanAccess OnChangeItemTrue(CityAgentCanAccess obj)
 {
     using (var db = new OcphDbContext())
     {
         try
         {
             obj.Id = db.CitiesAgentCanAccess.InsertAndGetLastID(obj);
             if (obj.Id > 0)
             {
                 return(obj);
             }
             else
             {
                 throw new SystemException(MessageCollection.Message(MessageType.SaveFail));
             }
         }
         catch (Exception ex)
         {
             throw new SystemException(ex.Message);
         }
     }
 }
示例#22
0
 public ManifestInformation InsertInformation(ManifestInformation obj)
 {
     using (var db = new OcphDbContext())
     {
         try
         {
             if (obj.Id <= 0)
             {
                 obj.Id = db.ManifestInformations.InsertAndGetLastID(obj);
                 if (obj.Id > 0)
                 {
                     return(obj);
                 }
                 else
                 {
                     throw new SystemException(MessageCollection.Message(MessageType.SaveFail));
                 }
             }
             else
             {
                 if (db.ManifestInformations.Update(O => new { O.Address, O.ArmadaName, O.Contact, O.CrewName, O.ReferenceNumber },
                                                    obj, O => O.Id == obj.Id))
                 {
                     return(obj);
                 }
                 else
                 {
                     throw new SystemException(MessageCollection.Message(MessageType.UpdateFaild));
                 }
             }
         }
         catch (Exception ex)
         {
             throw new SystemException(ex.Message);
         }
     }
 }
示例#23
0
        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");
                }
            }
        }
示例#24
0
        public Task <TracingModel> GetPenjualan(int STT)
        {
            try
            {
                var data = db.Penjualan.Where(x => x.Stt == STT)
                           .Include(x => x.Colly)
                           .Include(x => x.Reciver)
                           .Include(x => x.Shiper)
                           .Include(x => x.Invoicedetail)
                           .Include(x => x.Deliverystatus)
                           .Include(x => x.FromCityNavigation)
                           .Include(x => x.ToCityNavigation);


                var model = (from a in data
                             select new TracingModel
                {
                    Actived = a.Actived,
                    ChangeDate = a.ChangeDate,
                    Content = a.Content,
                    CustomerIdIsPay = a.CustomerIdIsPay,
                    DoNumber = a.DoNumber,
                    Etc = a.Etc,
                    IsPaid = a.IsPaid,
                    Note = a.Note,
                    PackingCosts = a.PackingCosts,
                    Pcs = a.Colly.Count,
                    PayType = a.PayType,
                    Id = a.Id,
                    ShiperName = a.Shiper.Name,
                    PortDestinationName = a.ToCityNavigation.CityName,
                    PortDestionationCode = a.ToCityNavigation.CityCode,
                    PortOriginCode = a.FromCityNavigation.CityCode,
                    PortOriginName = a.FromCityNavigation.CityName,
                    Price = a.Price,
                    ReciverName = a.Reciver.Name,
                    STT = a.Stt,
                    Tax = a.Tax,
                    Total = a.Total,
                    ReciveDate = a.Deliverystatus.ReciveDate,
                    ReciveName = a.Deliverystatus.ReciveName,
                    RecievePhone = a.Deliverystatus.Phone,
                    ReciveCondition = a.Deliverystatus.Description,
                    PortType = a.PortType,
                    TypeOfWeight = a.TypeOfWeight,
                    Weight = a.Colly.Sum(x => x.Weight),
                    UpdateDate = a.UpdateDate.Value,
                }).FirstOrDefault();


                if (model != null)
                {
                    var packlists = db.Packinglist.Where(O => O.PenjualanId == model.Id).AsEnumerable().GroupBy(O => O.ManifestId).ToList();
                    model.Manifests = new List <Manifestoutgoing>();
                    foreach (var item in packlists)
                    {
                        var manifest = db.Manifestoutgoing.Where(O => O.Id == item.Key)
                                       .Include(x => x.DestinationNavigation)
                                       .Include(x => x.OriginNavigation)
                                       .Include(x => x.Information).FirstOrDefault();
                        if (manifest != null)
                        {
                            model.Manifests.Add(manifest);
                        }
                    }
                    return(Task.FromResult(model));
                }
                else
                {
                    throw new SystemException(MessageCollection.Message(MessageType.NotFound));
                }
            }
            catch (Exception ex)
            {
                throw new SystemException(ex.Message);
            }
        }