Beispiel #1
0
        public IActionResult vendorAdd([FromBody] trSellingShipperDetailVendor value)
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("fullname")))
            {
                return(RedirectToAction("index", "login"));
            }

            string   user   = HttpContext.Session.GetString("fullname");
            DateTime txDate = DateTime.Now;

            try
            {
                value.isActive  = true;
                value.createdBy = user;
                value.createdOn = txDate;
                value.updatedBy = user;
                value.updatedOn = txDate;

                var context = new ValidationContext(value, serviceProvider: null, items: null);
                var results = new List <ValidationResult>();
                var isValid = Validator.TryValidateObject(value, context, results, true);

                List <string> errorMessage = new List <string>();
                if (value.sellingShipperDetailId == 0)
                {
                    errorMessage.Add("Mohon memilih salah satu detail");
                }
                if (value.vendorId == 0)
                {
                    errorMessage.Add("Vendor harus di isi");
                }

                if ((!isValid) || (errorMessage.Count > 0))
                {
                    foreach (ValidationResult validationResult in results)
                    {
                        errorMessage.Add(validationResult.ErrorMessage);
                    }

                    return(Ok(new { status = 400, message = errorMessage }));
                }

                mContext.trSellingShipperDetailVendor.Add(value);
                mContext.SaveChanges();

                return(Ok(new { status = 200, message = value.id }));
            }
            catch (Exception ex)
            {
                return(Ok(new { status = 409, message = ex.Message }));
            }
        }
Beispiel #2
0
        public IActionResult detailAdd([FromBody] trSellingShipperDetailModel value)
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("fullname")))
            {
                return(RedirectToAction("index", "login"));
            }

            string   user   = HttpContext.Session.GetString("fullname");
            DateTime txDate = DateTime.Now;

            try
            {
                var context = new ValidationContext(value, serviceProvider: null, items: null);
                var results = new List <ValidationResult>();
                var isValid = Validator.TryValidateObject(value, context, results, true);

                List <string> errorMessage = new List <string>();
                if (value.serviceId == 0)
                {
                    errorMessage.Add("Item Of Service harus di isi");
                }
                if (value.portOfDestinationId == 0)
                {
                    errorMessage.Add("Port Of Destination harus di isi");
                }
                if (value.locationId == 0)
                {
                    errorMessage.Add("Location harus di isi");
                }
                if (value.consigneeId == 0)
                {
                    errorMessage.Add("Consignee harus di isi");
                }
                if (value.containerId == 0)
                {
                    errorMessage.Add("Container harus di isi");
                }
                if (value.currencyId == 0)
                {
                    errorMessage.Add("Currency harus di isi");
                }
                if (value.taxId23 == 0)
                {
                    errorMessage.Add("% tax 23 harus di isi");
                }
                if (value.taxIdvat == 0)
                {
                    errorMessage.Add("% vat harus di isi");
                }
                if (value.orderId == 0)
                {
                    errorMessage.Add("Invoice Group harus di isi");
                }
                if (value.vendorId == 0)
                {
                    errorMessage.Add("CoLoader harus di isi");
                }

                if ((!isValid) || (errorMessage.Count > 0))
                {
                    foreach (ValidationResult validationResult in results)
                    {
                        errorMessage.Add(validationResult.ErrorMessage);
                    }

                    return(Ok(new { status = 400, message = errorMessage }));
                }

                //add condition if detail already save
                trSellingShipperDetailVendor checking =
                    mContext.trSellingShipperDetailVendor
                    .Where(x => x.isActive == true &&
                           x.sellingShipperId == value.sellingShipperId &&
                           x.sellingShipperDetailId == value.id &&
                           x.containerId == value.containerId &&
                           x.currencyId == value.currencyId &&
                           x.portOfDestinationId == value.portOfDestinationId)
                    .FirstOrDefault();

                if (checking is null)
                {
                    trSellingShipperDetail item = new trSellingShipperDetail();
                    item.sellingShipperId    = value.sellingShipperId;
                    item.serviceId           = value.serviceId;
                    item.portOfDestinationId = value.portOfDestinationId;
                    item.ofEmkl            = value.ofEmkl;
                    item.locationId        = value.locationId;
                    item.consigneeId       = value.consigneeId;
                    item.containerId       = value.containerId;
                    item.currencyId        = value.currencyId;
                    item.truckingCondition = value.truckingCondition; //1: Single; 2: Double;
                    item.taxId23           = value.taxId23;
                    item.taxIdvat          = value.taxIdvat;
                    item.price             = value.price;
                    item.remark            = value.remark;
                    item.orderId           = value.orderId;
                    item.allIn             = value.allIn;
                    item.isActive          = true;
                    item.createdBy         = user;
                    item.createdOn         = txDate;
                    item.updatedBy         = user;
                    item.updatedOn         = txDate;

                    mContext.trSellingShipperDetail.Add(item);
                    mContext.SaveChanges();

                    trSellingShipperDetailVendor refund = new trSellingShipperDetailVendor();
                    refund.sellingShipperId       = value.sellingShipperId;
                    refund.sellingShipperDetailId = item.id;
                    refund.containerId            = value.containerId;
                    refund.currencyId             = value.currencyId;
                    refund.portOfDestinationId    = value.portOfDestinationId;
                    refund.operationCost          = value.operationCost;
                    refund.operationCostType      = value.operationCostType;//1: Percentage; 2: Amount;
                    refund.payable    = value.payable;
                    refund.vendorId   = value.vendorId;
                    refund.vendorCode = mContext.mtVendor.Where(x => x.isActive == true && x.id == value.vendorId).Select(x => x.code).FirstOrDefault();
                    refund.vendorName = mContext.mtVendor.Where(x => x.isActive == true && x.id == value.vendorId).Select(x => x.name).FirstOrDefault();
                    refund.isActive   = true;
                    refund.createdBy  = user;
                    refund.createdOn  = txDate;
                    refund.updatedBy  = user;
                    refund.updatedOn  = txDate;

                    mContext.trSellingShipperDetailVendor.Add(refund);
                    mContext.SaveChanges();

                    return(Ok(new { status = 200, message = new { detailId = item.id, vendorId = refund.id, vendorCode = refund.vendorCode, vendorName = refund.vendorName } }));
                }
                else
                {
                    trSellingShipperDetailVendor refund = new trSellingShipperDetailVendor();
                    refund.sellingShipperId       = checking.sellingShipperId;
                    refund.sellingShipperDetailId = checking.sellingShipperDetailId;
                    refund.containerId            = value.containerId;
                    refund.currencyId             = value.currencyId;
                    refund.portOfDestinationId    = value.portOfDestinationId;
                    refund.operationCost          = value.operationCost;
                    refund.operationCostType      = value.operationCostType;//1: Percentage; 2: Amount;
                    refund.payable    = value.payable;
                    refund.vendorId   = value.vendorId;
                    refund.vendorCode = mContext.mtVendor.Where(x => x.isActive == true && x.id == value.vendorId).Select(x => x.code).FirstOrDefault();
                    refund.vendorName = mContext.mtVendor.Where(x => x.isActive == true && x.id == value.vendorId).Select(x => x.name).FirstOrDefault();
                    refund.isActive   = true;
                    refund.createdBy  = user;
                    refund.createdOn  = txDate;
                    refund.updatedBy  = user;
                    refund.updatedOn  = txDate;

                    mContext.trSellingShipperDetailVendor.Add(refund);
                    mContext.SaveChanges();

                    return(Ok(new { status = 201, message = new { vendorId = refund.id, vendorCode = refund.vendorCode, vendorName = refund.vendorName } }));
                }
            }
            catch (Exception ex)
            {
                return(Ok(new { status = 409, message = ex.Message }));
            }
        }