private InquiryBag ConvertInquiryItemToInquiryBag(InquiryItem item)
 {
     return(new InquiryBag
     {
         CustomerId = item.Inquiry.CustomerId,
         CustomerName = item.Inquiry.Customer.Name,
         CustomerAddress = item.Inquiry.Customer.InquiryAddress,
         CustomerTel = item.Inquiry.Customer.InquiryTel,
         Id = item.Id,
         InquiryId = item.InquiryId,
         ProductId = item.ProductId,
         DateTime = item.Inquiry.DateTime.Substring(0, 10),
         ProductName = item.Product.Title,
         Amount = item.Amount,
         PricePerUnit = item.PricePerUnit,
         PricePerKilo = item.PricePerKilo,
         TotalPrice = item.TotalPrice,
         TotalWeight = item.TotalWeight,
         HDPEPrice = item.HDPEPrice,
         ReasonForFailure = item.ReasonForFailure,
         NominalWeightPerMeter = item.NominalWeightPerMeter,
         IsSuccessful = item.IsSuccessful,
         Comments = item.Comments,
         WasherPrice = item.WasherPrice,
         InquiryTotalPrice = item.Inquiry.InquiryItemsPriceSummedUp
     });
 }
        public ActionResult Add(InquiryBag bag)
        {
            InquiryItem item = new InquiryItem()
            {
                Id                    = Guid.NewGuid(),
                Amount                = bag.Amount,
                Comments              = bag.Comments,
                HDPEPrice             = bag.HDPEPrice,
                InquiryId             = bag.InquiryId,
                IsSuccessful          = bag.IsSuccessful,
                NominalWeightPerMeter = bag.NominalWeightPerMeter,
                PricePerKilo          = Math.Ceiling((bag.Amount * bag.PricePerUnit) / bag.TotalWeight),
                PricePerUnit          = bag.PricePerUnit,
                TotalWeight           = bag.TotalWeight,
                ProductId             = bag.ProductId,
                ReasonForFailure      = bag.ReasonForFailure,
                WasherPrice           = bag.WasherPrice,
                TotalPrice            = (bag.Amount * bag.PricePerUnit)
            };

            context.InquiryItems.Add(item);
            context.SaveChanges();
            ViewBag.ModelOperatedId = item.Id;
            return(RedirectToAction("Index", new { area = "commerce", controller = "Inquiries" }));
        }
        public ActionResult Edit(Guid id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            InquiryItem inquiryItem = context.InquiryItems.Include("Product").Include("Inquiry.Customer").Where(i => i.Id.Equals(id)).FirstOrDefault();
            InquiryBag  inquiryBag  = null;

            if (inquiryItem != null)
            {
                inquiryBag = ConvertInquiryItemToInquiryBag(inquiryItem);
            }
            return(View("~/Areas/Commerce/Views/InquiriesRelated/Inquiries/Edit.cshtml", inquiryBag));
        }
        public ActionResult Edit(InquiryBag bag)
        {
            InquiryItem inquiryItem = context.InquiryItems.Find(bag.Id);

            inquiryItem.IsSuccessful          = bag.IsSuccessful;
            inquiryItem.ProductId             = bag.ProductId;
            inquiryItem.Amount                = bag.Amount;
            inquiryItem.Comments              = bag.Comments;
            inquiryItem.HDPEPrice             = bag.HDPEPrice;
            inquiryItem.IsSuccessful          = bag.IsSuccessful;
            inquiryItem.NominalWeightPerMeter = bag.NominalWeightPerMeter;
            inquiryItem.PricePerUnit          = bag.PricePerUnit;
            inquiryItem.ReasonForFailure      = bag.ReasonForFailure;
            inquiryItem.TotalPrice            = bag.Amount * bag.PricePerUnit;
            inquiryItem.PricePerKilo          = Math.Ceiling(inquiryItem.TotalPrice / bag.TotalWeight);
            inquiryItem.WasherPrice           = bag.WasherPrice;
            context.Entry(inquiryItem).State  = System.Data.Entity.EntityState.Modified;
            context.SaveChanges();
            ViewBag.ModelOperatedId = inquiryItem.Id.ToString();
            return(RedirectToAction("Index", new { area = "commerce", controller = "Inquiries" }));
        }