Exemple #1
0
        public int UpdateDispositionNotePosition(UpdatePositionFormDto form)
        {
            var models = _dbContext.GarmentDispositionPurchases.Include(item => item.GarmentDispositionPurchaseItems).ThenInclude(detail => detail.GarmentDispositionPurchaseDetails).Where(entity => form.Ids.Contains((int)entity.Id)).ToList();

            models = models.Select(model =>
            {
                model.Position = form.Position;
                if (form.Position == PurchasingGarmentExpeditionPosition.SendToCashier)
                {
                    model.GarmentDispositionPurchaseItems = model.GarmentDispositionPurchaseItems.Select(item =>
                    {
                        var previousVerifiedAmount = _dbContext.GarmentDispositionPurchaseItems.Where(t => t.EPOId == item.EPOId).Sum(t => t.VerifiedAmount);
                        item.VerifiedAmount        = (item.VATAmount + item.GarmentDispositionPurchaseDetails.Sum(detail => detail.PaidPrice) - item.IncomeTaxAmount) + previousVerifiedAmount;
                        return(item);
                    }).ToList();
                }
                else if (form.Position == PurchasingGarmentExpeditionPosition.SendToPurchasing)
                {
                    model.GarmentDispositionPurchaseItems = model.GarmentDispositionPurchaseItems.Select(item =>
                    {
                        item.VerifiedAmount = 0;
                        return(item);
                    }).ToList();
                }
                else
                {
                    model.GarmentDispositionPurchaseItems = model.GarmentDispositionPurchaseItems.Select(item =>
                    {
                        //item.VerifiedAmount = 0;
                        return(item);
                    }).ToList();
                }
                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);

                return(model);
            }).ToList();

            _dbContext.GarmentDispositionPurchases.UpdateRange(models);
            return(_dbContext.SaveChanges());
        }
        public async Task <int> Update(int id, InternalPurchaseOrder internalPurchaseOrder, string user)
        {
            int Updated = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    var m = this.dbSet.AsNoTracking()
                            .Include(d => d.Items)
                            .Single(pr => pr.Id == id && !pr.IsDeleted);

                    if (m != null)
                    {
                        EntityExtension.FlagForUpdate(internalPurchaseOrder, user, "Facade");

                        foreach (var item in internalPurchaseOrder.Items)
                        {
                            EntityExtension.FlagForUpdate(item, user, "Facade");
                        }

                        this.dbContext.Update(internalPurchaseOrder);
                        Updated = await dbContext.SaveChangesAsync();

                        transaction.Commit();
                    }
                    else
                    {
                        throw new Exception("Error while updating data");
                    }
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Updated);
        }
Exemple #3
0
        public async Task <IActionResult> PutAccountProfile(int id, [FromBody] PersonalDataFormViewModel accountProfile)
        {
            /*if (id != accountProfile.Id)
             * {
             *  return BadRequest();
             * }*/

            try
            {
                VerifyUser();
                var model = await _context.AccountInformations.FindAsync(id);

                {
                    model.EmployeeID          = accountProfile.EmployeeId;
                    model.Fullname            = accountProfile.Fullname;
                    model.Username            = accountProfile.Username;
                    model.Dob                 = accountProfile.DOB;
                    model.Gender              = accountProfile.Gender;
                    model.Religion            = accountProfile.Religion;
                    model.Email               = accountProfile.Email;
                    model.EmployeePhoneNumber = accountProfile.EmployeePhoneNumber;
                };
                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
                _context.AccountInformations.Update(model);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccountProfileExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #4
0
        public async Task <int> UpdateAsync(int id, GarmentInvoicePaymentModel model)
        {
            GarmentInvoicePaymentModel exist = DbSet
                                               .Include(d => d.Items)
                                               .Single(dispo => dispo.Id == id && !dispo.IsDeleted);

            exist.PaymentDate = model.PaymentDate;
            exist.BuyerId     = model.BuyerId;
            exist.BuyerCode   = model.BuyerCode;
            exist.BuyerName   = model.BuyerName;
            exist.BGNo        = model.BGNo;
            exist.Remark      = model.Remark;

            foreach (var item in exist.Items)
            {
                GarmentInvoicePaymentItemModel itemModel = model.Items.FirstOrDefault(prop => prop.Id.Equals(item.Id));

                if (itemModel == null)
                {
                    EntityExtension.FlagForDelete(item, IdentityService.Username, UserAgent, true);
                }
                else
                {
                    EntityExtension.FlagForUpdate(item, IdentityService.Username, UserAgent);
                }
            }
            foreach (var newItem in model.Items)
            {
                if (newItem.Id == 0)
                {
                    exist.Items.Add(newItem);
                    EntityExtension.FlagForCreate(newItem, IdentityService.Username, UserAgent);
                }
            }


            EntityExtension.FlagForUpdate(exist, IdentityService.Username, UserAgent);

            return(await DbContext.SaveChangesAsync());
        }
Exemple #5
0
        public async Task <int> CashierAccepted(List <int> ids)
        {
            var models = _dbContext.GarmentPurchasingExpeditions.Where(entity => ids.Contains(entity.Id)).ToList();

            models = models.Select(model =>
            {
                model.CashierAccepted(_identityService.Username);

                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
                return(model);
            }).ToList();


            _dbContext.GarmentPurchasingExpeditions.UpdateRange(models);
            var result = await _dbContext.SaveChangesAsync();

            var internalNoteIds = models.Select(model => model.InternalNoteId).ToList();

            await UpdateInternalNotePosition(internalNoteIds, GarmentPurchasingExpeditionPosition.CashierAccepted);

            return(result);
        }
        public int EPOClose(int id, string user)
        {
            int Updated = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    var m = this.dbSet
                            .Include(d => d.Items)
                            .ThenInclude(d => d.Details)
                            .SingleOrDefault(epo => epo.Id == id && !epo.IsDeleted);

                    EntityExtension.FlagForUpdate(m, user, "Facade");
                    m.IsClosed = true;

                    foreach (var item in m.Items)
                    {
                        EntityExtension.FlagForUpdate(item, user, "Facade");
                        foreach (var detail in item.Details)
                        {
                            EntityExtension.FlagForUpdate(detail, user, "Facade");
                        }
                        InternalPurchaseOrder internalPurchaseOrder = this.dbContext.InternalPurchaseOrders.FirstOrDefault(s => s.Id == item.POId);
                        internalPurchaseOrder.IsClosed = true;
                    }

                    Updated = dbContext.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Updated);
        }
Exemple #7
0
        public async Task <int> VoidAccountingAccepted(int id)
        {
            var model = _dbContext.GarmentDispositionExpeditions.FirstOrDefault(entity => entity.Id == id);

            model.VoidAccounting(_identityService.Username);
            EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
            _dbContext.GarmentDispositionExpeditions.Update(model);

            var httpClient = _serviceProvider.GetService <IHttpClientService>();
            var updateDispositionNotePositionData = new
            {
                Ids = new List <int>()
                {
                    model.DispositionNoteId
                },
                model.Position
            };

            await httpClient.PutAsync($"{APIEndpoint.Purchasing}garment-purchasing-expeditions/disposition-notes/position", new StringContent(JsonConvert.SerializeObject(updateDispositionNotePositionData), Encoding.UTF8, General.JsonMediaType));

            return(_dbContext.SaveChanges());
        }
        public int Posting(List <int> memoIds)
        {
            if (memoIds.Count > 0)
            {
                var memoDocuments = _dbContext.MemoDetailGarmentPurchasings.Where(entity => memoIds.Contains(entity.Id)).ToList();
                var memoDetails   = _dbContext.MemoDetailGarmentPurchasingDetails.Where(entity => memoIds.Contains(entity.MemoDetailId)).Select(entity => new { entity.Id, entity.MemoDetailId, entity.MemoAmount, entity.GarmentDeliveryOrderId }).ToList();

                foreach (var detail in memoDetails)
                {
                    var memoDocument = memoDocuments.FirstOrDefault(element => element.Id == detail.MemoDetailId);


                    _debtBalance.UpdateFromMemo(detail.GarmentDeliveryOrderId, detail.Id, memoDocument.MemoNo, detail.MemoAmount, memoDocument.GarmentCurrenciesRate);

                    memoDocument.IsPosted = true;
                    EntityExtension.FlagForUpdate(memoDocument, _identityService.Username, UserAgent);
                    _dbContext.SaveChanges();
                }
            }

            return(memoIds.Count);
        }
Exemple #9
0
        public async Task <int> CreateAsync(VbVerificationViewModel viewmodel)
        {
            //using (var transaction = _dbContext.Database.BeginTransaction())
            //{

            var m = dbSet.SingleOrDefault(e => e.Id == viewmodel.numberVB.Id);

            EntityExtension.FlagForUpdate(m, _identityService.Username, UserAgent);
            m.isVerified    = viewmodel.isVerified;
            m.isNotVeridied = viewmodel.isNotVeridied;
            m.VerifiedName  = _identityService.Username;

            m.VerifiedDate = (DateTimeOffset)viewmodel.VerifyDate;

            if (string.IsNullOrEmpty(viewmodel.Reason))
            {
                m.Reason_NotVerified = "";
            }
            else
            {
                m.Reason_NotVerified = viewmodel.Reason;
            }

            //transaction.Commit();
            //}

            await _dbContext.SaveChangesAsync();

            if (m.isVerified)
            {
                await _expeditionService.VerifiedToCashier(m.Id);
            }
            else
            {
                await _expeditionService.Reject(m.Id, viewmodel.Reason);
            }

            return(m.Id);
        }
Exemple #10
0
        public int Update(int id, FormDto form)
        {
            var model = _dbContext.VBRealizationDocuments.FirstOrDefault(entity => entity.Id == id);

            model.UpdatePosition(VBRealizationPosition.Purchasing, _identityService.Username, UserAgent);

            if (form.VBRequestDocument != null && form.VBRequestDocument.Id.GetValueOrDefault() > 0)
            {
                var vbRequest = _dbContext.VBRequestDocuments.FirstOrDefault(entity => entity.Id == form.VBRequestDocument.Id.GetValueOrDefault());
                model.Update(vbRequest);
                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
            }

            var httpClientService = _serviceProvider.GetService <IHttpClientService>();

            var items = _dbContext.VBRealizationDocumentExpenditureItems.Where(entity => entity.VBRealizationDocumentId == id).ToList();

            items = items.Select(element =>
            {
                EntityExtension.FlagForDelete(element, _identityService.Username, UserAgent);
                var result = httpClientService.PutAsync($"{APIEndpoint.Purchasing}vb-request-po-external/spb/{element.UnitPaymentOrderId}?division={model.SuppliantDivisionName}", new StringContent("{}", Encoding.UTF8, General.JsonMediaType)).Result;
                return(element);
            }).ToList();
            _dbContext.VBRealizationDocumentExpenditureItems.UpdateRange(items);

            var details = _dbContext.VBRealizationDocumentUnitCostsItems.Where(entity => entity.VBRealizationDocumentId == id).ToList();

            details = details.Select(element =>
            {
                EntityExtension.FlagForDelete(element, _identityService.Username, UserAgent);
                return(element);
            }).ToList();
            _dbContext.VBRealizationDocumentUnitCostsItems.UpdateRange(details);

            AddItems(id, form.Items, form.SuppliantUnit.Division.Name);
            AddUnitCosts(model.Id, form.Items.SelectMany(element => element.UnitPaymentOrder.UnitCosts).ToList());

            return(id);
        }
        public async Task <int> Delete(int id)
        {
            int Deleted = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    var garmentUnitDeliveryOrder = dbSet
                                                   .Include(m => m.Items)
                                                   .SingleOrDefault(m => m.Id == id);

                    EntityExtension.FlagForDelete(garmentUnitDeliveryOrder, identityService.Username, USER_AGENT);
                    foreach (var garmentUnitDeliveryOrderItem in garmentUnitDeliveryOrder.Items)
                    {
                        EntityExtension.FlagForDelete(garmentUnitDeliveryOrderItem, identityService.Username, USER_AGENT);

                        GarmentDeliveryOrderDetail doDetail = dbContext.GarmentDeliveryOrderDetails.Single(s => s.Id.Equals(garmentUnitDeliveryOrderItem.DODetailId));

                        doDetail.ReturQuantity = doDetail.ReturQuantity - garmentUnitDeliveryOrderItem.ReturQuantity;

                        GarmentUnitReceiptNoteItem garmentUnitReceiptNoteItem = dbContext.GarmentUnitReceiptNoteItems.Single(s => s.Id == garmentUnitDeliveryOrderItem.URNItemId);
                        EntityExtension.FlagForUpdate(garmentUnitReceiptNoteItem, identityService.Username, USER_AGENT);
                        garmentUnitReceiptNoteItem.OrderQuantity = garmentUnitReceiptNoteItem.OrderQuantity - (decimal)garmentUnitDeliveryOrderItem.Quantity;
                    }

                    Deleted = await dbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Deleted);
        }
Exemple #12
0
        public async Task <int> SendToPurchasingRejected(int id, string remark)
        {
            var model = _dbContext.GarmentPurchasingExpeditions.FirstOrDefault(entity => entity.Id == id);

            model.SendToPurchasingRejected(_identityService.Username, remark);
            EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
            _dbContext.GarmentPurchasingExpeditions.Update(model);

            var httpClient = _serviceProvider.GetService <IHttpClientService>();
            var updateInternalNotePositionData = new
            {
                Ids = new List <int>()
                {
                    model.InternalNoteId
                },
                Position = GarmentPurchasingExpeditionPosition.SendToPurchasing
            };

            await httpClient.PutAsync($"{APIEndpoint.Purchasing}garment-purchasing-expeditions/internal-notes/position", new StringContent(JsonConvert.SerializeObject(updateInternalNotePositionData), Encoding.UTF8, General.JsonMediaType));

            return(_dbContext.SaveChanges());
        }
Exemple #13
0
        public async Task <int> Create(DeliveryOrder model, string username)
        {
            int Created = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    EntityExtension.FlagForCreate(model, username, USER_AGENT);

                    foreach (var item in model.Items)
                    {
                        EntityExtension.FlagForCreate(item, username, USER_AGENT);

                        foreach (var detail in item.Details)
                        {
                            EntityExtension.FlagForCreate(detail, username, USER_AGENT);

                            ExternalPurchaseOrderDetail externalPurchaseOrderDetail = this.dbContext.ExternalPurchaseOrderDetails.SingleOrDefault(m => m.Id == detail.EPODetailId);
                            externalPurchaseOrderDetail.DOQuantity += detail.DOQuantity;
                            EntityExtension.FlagForUpdate(externalPurchaseOrderDetail, username, USER_AGENT);
                            SetStatus(externalPurchaseOrderDetail, detail, username);
                        }
                    }

                    this.dbSet.Add(model);
                    Created = await dbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Created);
        }
        public async Task <IActionResult> PutEmployeeData(int id, [FromBody] EmployeeDataFormViewModel employeeData)
        {
            /*if (id != familyData.Id)
             * {
             *  return BadRequest();
             * }*/

            try
            {
                VerifyUser();
                var model = await _context.AccountInformations.FindAsync(id);

                {
                    model.JobTitleName    = employeeData.JobTitleName;
                    model.Department      = employeeData.Department;
                    model.Status          = employeeData.Status;
                    model.JoinDate        = employeeData.JoinDate;
                    model.CoorporateEmail = employeeData.CoorporateEmail;
                    model.SkillSet        = employeeData.SkillSet;
                };
                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
                _context.AccountInformations.Update(model);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccountProfileExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #15
0
        public Task <int> UpdateAsync(int id, VbWithPORequestViewModel viewmodel)
        {
            var model = MappingData2(id, viewmodel);

            EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);

            var itemIds = _dbContext.VbRequestsDetails.Where(entity => entity.VBId == id).Select(entity => entity.Id).ToList();

            foreach (var itemId in itemIds)
            {
                var item = model.VbRequestDetail.FirstOrDefault(element => element.Id == itemId);
                //if (item == null)
                //{
                var itemToDelete = _dbContext.VbRequestsDetails.FirstOrDefault(entity => entity.Id == itemId);
                EntityExtension.FlagForDelete(itemToDelete, _identityService.Username, UserAgent);
                _dbContext.VbRequestsDetails.Update(itemToDelete);
                //}
                //else
                //{
                //    EntityExtension.FlagForUpdate(item, _identityService.Username, UserAgent);
                //    _dbContext.VbRequestsDetails.Update(item);
                //}
            }

            foreach (var item in model.VbRequestDetail)
            {
                if (item.Id <= 0)
                {
                    EntityExtension.FlagForCreate(item, _identityService.Username, UserAgent);
                    _dbContext.VbRequestsDetails.Add(item);
                }
            }


            _dbContext.VbRequests.Update(model);

            return(_dbContext.SaveChangesAsync());
        }
        public async Task <int> Create(GarmentUnitDeliveryOrder garmentUnitDeliveryOrder)
        {
            int Created = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    garmentUnitDeliveryOrder.Items = garmentUnitDeliveryOrder.Items.Where(x => x.IsSave).ToList();

                    EntityExtension.FlagForCreate(garmentUnitDeliveryOrder, identityService.Username, USER_AGENT);

                    garmentUnitDeliveryOrder.UnitDONo = await GenerateNo(garmentUnitDeliveryOrder);

                    foreach (var garmentUnitDeliveryOrderItem in garmentUnitDeliveryOrder.Items)
                    {
                        EntityExtension.FlagForCreate(garmentUnitDeliveryOrderItem, identityService.Username, USER_AGENT);

                        GarmentUnitReceiptNoteItem garmentUnitReceiptNoteItem = dbContext.GarmentUnitReceiptNoteItems.Single(s => s.Id == garmentUnitDeliveryOrderItem.URNItemId);
                        EntityExtension.FlagForUpdate(garmentUnitReceiptNoteItem, identityService.Username, USER_AGENT);
                        garmentUnitReceiptNoteItem.OrderQuantity = garmentUnitReceiptNoteItem.OrderQuantity + (decimal)garmentUnitDeliveryOrderItem.Quantity;
                    }

                    dbSet.Add(garmentUnitDeliveryOrder);

                    Created = await dbContext.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Created);
        }
        public void BOCancel(int id, GarmentBookingOrder model)
        {
            double cancelsQuantity = 0;

            cancelsQuantity = model.OrderQuantity - model.ConfirmedQuantity;

            model.CanceledQuantity += cancelsQuantity;
            model.OrderQuantity    -= cancelsQuantity;
            model.CanceledDate      = DateTimeOffset.Now;
            foreach (var item in model.Items)
            {
                GarmentBookingOrderItemsLogic.UpdateAsync((int)item.Id, item);
            }

            if (model.ConfirmedQuantity == 0)
            {
                model.IsCanceled = true;
            }
            EntityExtension.FlagForUpdate(model, IdentityService.Username, "sales-service");

            if (model.IsBlockingPlan == true)
            {
                var blockingPlan = DbContext.GarmentSewingBlockingPlans.FirstOrDefault(b => b.BookingOrderId == model.Id);
                if (blockingPlan != null)
                {
                    if (model.OrderQuantity == 0)
                    {
                        blockingPlan.Status = "Booking Dibatalkan";
                    }
                    else if (model.OrderQuantity > 0 && model.CanceledQuantity > 0)
                    {
                        blockingPlan.Status = "Booking Ada Perubahan";
                    }
                }
            }

            DbSet.Update(model);
        }
Exemple #18
0
        public async Task <int> SendToVerification(SendToVerificationAccountingFormDto form)
        {
            var models = new List <GarmentDispositionExpeditionModel>();

            foreach (var item in form.Items)
            {
                var query = _dbContext.GarmentDispositionExpeditions.Where(entity => entity.Position == GarmentPurchasingExpeditionPosition.SendToVerification);
                var list  = query.Where(entity => entity.DispositionNoteNo.Contains(item.DispositionNote.DocumentNo)).ToList();

                var model = new GarmentDispositionExpeditionModel(item.DispositionNote.Id, item.DispositionNote.DocumentNo, item.DispositionNote.Date, item.DispositionNote.DueDate, item.DispositionNote.SupplierId, item.DispositionNote.SupplierName, item.DispositionNote.VATAmount, item.DispositionNote.CurrencyVATAmount, item.DispositionNote.IncomeTaxAmount, item.DispositionNote.CurrencyIncomeTaxAmount, item.DispositionNote.TotalPaid, item.DispositionNote.CurrencyTotalPaid, item.DispositionNote.CurrencyId, item.DispositionNote.CurrencyCode, item.Remark, item.DispositionNote.DPPAmount, item.DispositionNote.CurrencyDPPAmount, item.DispositionNote.SupplierCode, item.DispositionNote.CurrencyRate, item.DispositionNote.ProformaNo, item.DispositionNote.Category);
                model.SendToVerification(_identityService.Username);

                EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent);
                models.Add(model);

                foreach (var expedition in list)
                {
                    expedition.SendToPurchasingRejected(_identityService.Username, "");

                    EntityExtension.FlagForUpdate(expedition, _identityService.Username, UserAgent);
                    models.Add(expedition);
                }
            }
            _dbContext.GarmentDispositionExpeditions.UpdateRange(models);

            var httpClient = _serviceProvider.GetService <IHttpClientService>();
            var updateDispositionNotePositionData = new
            {
                Ids      = models.Select(element => element.DispositionNoteId).ToList(),
                Position = GarmentPurchasingExpeditionPosition.SendToVerification
            };



            await httpClient.PutAsync($"{APIEndpoint.Purchasing}garment-purchasing-expeditions/disposition-notes/position", new StringContent(JsonConvert.SerializeObject(updateDispositionNotePositionData), Encoding.UTF8, General.JsonMediaType));

            return(_dbContext.SaveChanges());
        }
Exemple #19
0
        public async Task <IActionResult> PutFamilyData(int id, [FromBody] FamilyDataFormViewModel familyData)
        {
            /*if (id != familyData.Id)
             * {
             *  return BadRequest();
             * }*/

            try
            {
                VerifyUser();
                var model = await _context.FamilyDatas.FindAsync(id);

                {
                    model.FullNameOfFamily = familyData.FullNameOfFamily;
                    model.Relationship     = familyData.Relationship;
                    model.DOBFamily        = familyData.DOBFamily;
                    model.Gender           = familyData.Gender;
                    model.Religion         = familyData.Religion;
                    model.KTPNumber        = familyData.KTPNumber;
                };
                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
                _context.FamilyDatas.Update(model);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccountProfileExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #20
0
        public async Task <int> DistributeCC(List <long> listId, string user)
        {
            int Updated = 0;

            using (var transaction = DbContext.Database.BeginTransaction())
            {
                try
                {
                    var listData = DbSet.
                                   Where(w => listId.Contains(w.Id))
                                   .ToList();

                    foreach (var data in listData)
                    {
                        EntityExtension.FlagForUpdate(data, user, USER_AGENT);
                        data.IsRODistributed    = true;
                        data.RODistributionDate = DateTimeOffset.Now;
                        data.RODistributionBy   = user;
                    }

                    Updated = await DbContext.SaveChangesAsync();

                    if (Updated < 1)
                    {
                        throw new Exception("No data updated");
                    }

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Updated);
        }
Exemple #21
0
        public override void UpdateAsync(long id, RO_Garment model)
        {
            if (model.RO_Garment_SizeBreakdowns != null)
            {
                HashSet <long> detailIds = roGarmentSizeBreakdownLogic.GetIds(id);

                foreach (var itemId in detailIds)
                {
                    RO_Garment_SizeBreakdown data = model.RO_Garment_SizeBreakdowns.FirstOrDefault(prop => prop.Id.Equals(itemId));
                    if (data == null)
                    {
                        RO_Garment_SizeBreakdown dataItem = DbContext.RO_Garment_SizeBreakdowns.FirstOrDefault(prop => prop.Id.Equals(itemId));
                        List <RO_Garment_SizeBreakdown_Detail> details = DbContext.RO_Garment_SizeBreakdown_Details.Where(a => a.RO_Garment_SizeBreakdownId.Equals(itemId)).ToList();
                        foreach (RO_Garment_SizeBreakdown_Detail detail in details)
                        {
                            EntityExtension.FlagForDelete(detail, IdentityService.Username, "sales-service");
                        }

                        EntityExtension.FlagForDelete(dataItem, IdentityService.Username, "sales-service");
                    }
                    else
                    {
                        roGarmentSizeBreakdownLogic.UpdateAsync(itemId, data);
                    }

                    foreach (RO_Garment_SizeBreakdown item in model.RO_Garment_SizeBreakdowns)
                    {
                        if (item.Id == 0)
                        {
                            roGarmentSizeBreakdownLogic.Create(item);
                        }
                    }
                }
            }

            EntityExtension.FlagForUpdate(model, IdentityService.Username, "sales-service");
            DbSet.Update(model);
        }
Exemple #22
0
        internal void UnpostRO(long id)
        {
            var model = DbSet.Single(m => m.Id == id);

            model.IsPosted = false;
            EntityExtension.FlagForUpdate(model, IdentityService.Username, "sales-service");

            var cc = DbContext.CostCalculationGarments.Single(m => m.Id == model.CostCalculationGarmentId);

            cc.IsValidatedROPPIC  = false;
            cc.ValidationPPICBy   = null;
            cc.ValidationPPICDate = DateTimeOffset.MinValue;

            cc.IsValidatedROSample  = false;
            cc.ValidationSampleBy   = null;
            cc.ValidationSampleDate = DateTimeOffset.MinValue;

            cc.IsValidatedROMD  = false;
            cc.ValidationMDBy   = null;
            cc.ValidationMDDate = DateTimeOffset.MinValue;

            EntityExtension.FlagForUpdate(cc, IdentityService.Username, "sales-service");
        }
Exemple #23
0
        public async Task <int> UpdateAsync(int id, ShipmentDocumentModel model)
        {
            EntityExtension.FlagForUpdate(model, _IdentityService.Username, _UserAgent);
            _DbSet.Update(model);
            foreach (var detail in model.Details)
            {
                EntityExtension.FlagForUpdate(detail, _IdentityService.Username, _UserAgent);
                _DetailDbSet.Update(detail);
                foreach (var item in detail.Items)
                {
                    EntityExtension.FlagForUpdate(item, _IdentityService.Username, _UserAgent);
                    _ItemDbSet.Update(item);
                    foreach (var packingReceiptItem in item.PackingReceiptItems)
                    {
                        EntityExtension.FlagForUpdate(packingReceiptItem, _IdentityService.Username, _UserAgent);
                        _PackingReceiptItemDbSet.Update(packingReceiptItem);
                    }
                }
            }

            CreateInventoryDocumentIn(model);
            return(await _DbContext.SaveChangesAsync());
        }
Exemple #24
0
        public override async void UpdateAsync(long id, SalesInvoiceModel model)
        {
            try
            {
                if (model.SalesInvoiceDetails != null)
                {
                    HashSet <long> detailIds = salesInvoiceDetailLogic.GetIds(id);
                    foreach (var itemId in detailIds)
                    {
                        SalesInvoiceDetailModel data = model.SalesInvoiceDetails.FirstOrDefault(prop => prop.Id.Equals(itemId));
                        if (data == null)
                        {
                            await salesInvoiceDetailLogic.DeleteAsync(itemId);
                        }
                        else
                        {
                            salesInvoiceDetailLogic.UpdateAsync(itemId, data);
                        }
                    }

                    foreach (SalesInvoiceDetailModel item in model.SalesInvoiceDetails)
                    {
                        if (item.Id == 0)
                        {
                            salesInvoiceDetailLogic.Create(item);
                        }
                    }
                }

                EntityExtension.FlagForUpdate(model, IdentityService.Username, "sales-service");
                DbSet.Update(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #25
0
        public async Task <IActionResult> PutEducationInfo(int id, [FromBody] EducationInfoFormViewModel educationInfo)
        {
            /*if (id != educationInfo.Id)
             * {
             *  return BadRequest();
             * }*/

            try
            {
                VerifyUser();
                var model = await _context.EducationInfos.FindAsync(id);

                {
                    model.Grade       = educationInfo.Grade;
                    model.Majors      = educationInfo.Majors;
                    model.Institution = educationInfo.Institution;
                    model.YearStart   = educationInfo.YearStart;
                    model.YearEnd     = educationInfo.YearEnd;
                };
                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
                _context.EducationInfos.Update(model);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EducationInfoExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #26
0
        public async Task <IActionResult> PutInformalEducation(int id, [FromBody] InformalEducationFormViewModel informalEducation)
        {
            /*if (id != informalEducation.Id)
             * {
             *  return BadRequest();
             * }*/

            try
            {
                VerifyUser();
                var model = await _context.InformalEducations.FindAsync(id);

                {
                    model.Description = informalEducation.Description;
                    model.JobPosition = informalEducation.JobPosition;
                    model.EndDate     = informalEducation.EndDate;
                    model.HeldBy      = informalEducation.HeldBy;
                    model.StartDate   = informalEducation.StartDate;
                };
                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
                _context.InformalEducations.Update(model);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InformalEducationExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #27
0
        public async Task <IActionResult> PutWorkingExperience(int id, [FromBody] WorkingExperienceFormViewModel workingExperience)
        {
            /*if (id != workingExperience.Id)
             * {
             *  return BadRequest();
             * }*/

            try
            {
                VerifyUser();
                var model = await _context.WorkingExperiences.FindAsync(id);

                {
                    model.Company = workingExperience.Company;
                    model.JobPositionExperience = workingExperience.JobPositionExperience;
                    model.TanggalMulai          = workingExperience.TanggalMulai;
                    model.TanggalSelesai        = workingExperience.TanggalSelesai;
                    model.Deskripsi             = workingExperience.Deskripsi;
                };
                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
                _context.WorkingExperiences.Update(model);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkingExperienceExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutAssets(int id, [FromBody] AssetFormViewModel asset)
        {
            /*if (id != informalEducation.Id)
             * {
             *  return BadRequest();
             * }*/

            try
            {
                VerifyUser();
                var model = await _context.Assets.FindAsync(id);

                {
                    model.AssetNumber           = asset.AssetNumber;
                    model.AssetName             = asset.AssetName;
                    model.AssetType             = asset.AssetType;
                    model.FullNameEmployeeAsset = asset.FullNameEmployeeAsset;
                    model.AcquisitionDate       = asset.AcquisitionDate;
                };
                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
                _context.Assets.Update(model);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!assetExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #29
0
        public int EPOApprove(List <GarmentExternalPurchaseOrder> ListEPO, string user)
        {
            int Updated = 0;

            using (var transaction = this.dbContext.Database.BeginTransaction())
            {
                try
                {
                    var Ids      = ListEPO.Select(d => d.Id).ToList();
                    var listData = this.dbSet
                                   .Where(m => Ids.Contains(m.Id) && !m.IsDeleted)
                                   .Include(d => d.Items)
                                   .ToList();
                    listData.ForEach(m =>
                    {
                        EntityExtension.FlagForUpdate(m, user, "Facade");
                        m.IsApproved = true;

                        foreach (var item in m.Items)
                        {
                            EntityExtension.FlagForUpdate(item, user, "Facade");
                        }
                    });

                    Updated = dbContext.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new Exception(e.Message);
                }
            }

            return(Updated);
        }
        private void SetNewActualBalanceByMonth(int month, int year, DailyBankTransactionModel model, decimal nominal)
        {
            var PreviousMonthBalance = GetPreviousMonthBalance(month, year);
            var NextMonthBalance     = GetNextMonthBalance(month, year);
            var NewMonthBalance      = new BankTransactionMonthlyBalanceModel
            {
                Month            = month,
                Year             = year,
                InitialBalance   = PreviousMonthBalance != null ? PreviousMonthBalance.RemainingBalance : 0,
                RemainingBalance = PreviousMonthBalance != null ? PreviousMonthBalance.RemainingBalance + (double)nominal : (double)nominal,
                AccountBankId    = model.AccountBankId
            };

            EntityExtension.FlagForCreate(NewMonthBalance, _IdentityService.Username, _UserAgent);
            _DbMonthlyBalanceSet.Add(NewMonthBalance);

            if (NextMonthBalance != null)
            {
                NextMonthBalance.InitialBalance    = NewMonthBalance.RemainingBalance;
                NextMonthBalance.RemainingBalance += (double)nominal;
                EntityExtension.FlagForUpdate(NextMonthBalance, _IdentityService.Username, _UserAgent);
                _DbMonthlyBalanceSet.Update(NextMonthBalance);
            }
        }