Exemplo n.º 1
0
        //-> EditLineItem
        private async Task <List <tblSaleOrderItem> > EditLineItem(int mastetID, SaleOrderEditDTO editDTO)
        {
            var list = new List <tblSaleOrderItem>();

            if (editDTO.items != null)
            {
                foreach (var item in editDTO.items)
                {
                    var record = new tblSaleOrderItem();

                    if (item.id == null)
                    {
                        record             = (tblSaleOrderItem)MappingHelper.MapDTOToDBClass <SaleOrderItemEditDTO, tblSaleOrderItem>(item, new tblSaleOrderItem());
                        record.createdDate = DateTime.Now;
                    }
                    else
                    {
                        record = await db.tblSaleOrderItems.FirstOrDefaultAsync(x => x.deleted == null && x.id == item.id);

                        record             = (tblSaleOrderItem)MappingHelper.MapDTOToDBClass <SaleOrderItemEditDTO, tblSaleOrderItem>(item, record);
                        record.updatedDate = DateTime.Now;
                    }

                    record.total       = record.quantity * record.price;
                    record.saleOrderID = mastetID;
                    if (item.id == null)
                    {
                        db.tblSaleOrderItems.Add(record);
                    }
                    await db.SaveChangesAsync();

                    list.Add(record);
                }
            }
            if (!string.IsNullOrEmpty(editDTO.deleteLineItemID))
            {
                var ids = editDTO.deleteLineItemID.Split(',');
                foreach (var id in ids)
                {
                    var itemID = int.Parse(id);
                    var item   = await db.tblSaleOrderItems.FirstOrDefaultAsync(x => x.deleted == null && x.id == itemID);

                    if (item != null)
                    {
                        item.deleted = 1;
                        await db.SaveChangesAsync();
                    }
                }
            }
            return(list);
        }
Exemplo n.º 2
0
 public async Task <JsonResult> Edit(SaleOrderEditDTO editDTO)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             throw new HttpException((int)HttpStatusCode.BadRequest, ConstantHelper.KEY_IN_REQUIRED_FIELD);
         }
         Response.StatusCode = 200;
         return(Json(await handler.Edit(editDTO), JsonRequestBehavior.AllowGet));
     }
     catch (HttpException)
     {
         return(Json(ConstantHelper.ERROR, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 3
0
        //-> Save
        public async Task <SaleOrderViewDTO> Edit(SaleOrderEditDTO editDTO)
        {
            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    editDTO              = StringHelper.TrimStringProperties(editDTO);
                    editDTO.date         = editDTO.date.ToDBDate();
                    editDTO.requiredDate = editDTO.requiredDate.ToDBDate();
                    var record = await db.tblSaleOrders.FirstOrDefaultAsync(r => r.deleted == null && r.id == editDTO.id);

                    if (record == null)
                    {
                        throw new HttpException((int)HttpStatusCode.NotFound, "NotFound");
                    }
                    editDTO.updatedDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    record             = (tblSaleOrder)MappingHelper.MapDTOToDBClass <SaleOrderEditDTO, tblSaleOrder>(editDTO, record);
                    record.updatedDate = DateTime.Now;
                    var         session = HttpContext.Current.Session;
                    UserViewDTO user    = (UserViewDTO)session["user"];
                    if (user != null)
                    {
                        record.updatedBy = user.id;
                    }
                    record.slor_LockBy = null;
                    record.slor_LockOn = null;
                    var lineItems = await EditLineItem(record.id, editDTO);

                    record.total = lineItems.Sum(item => item.total);
                    await db.SaveChangesAsync();

                    transaction.Commit();
                    return(await SelectByID(record.id));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw new Exception(ex.Message);
                }
            }
        }