public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            if (ModelState.IsValid)
            {
                Product product = _ProductService.Find(vm.id);


                ActivityLog al = new ActivityLog()
                {
                    ActivityType = (int)ActivityTypeContants.Deleted,
                    CreatedBy    = User.Identity.Name,
                    CreatedDate  = DateTime.Now,
                    DocId        = vm.id,
                    UserRemark   = vm.Reason,
                    Narration    = "Bom is deleted with Name:" + product.ProductName,
                    DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(TransactionDocCategoryConstants.SaleOrder).DocumentTypeId,
                    UploadDate   = DateTime.Now,
                };
                new ActivityLogService(_unitOfWork).Create(al);


                IEnumerable <BomDetail> bomdetail = _BomDetailService.GetBomDetailList(vm.id);
                //Mark ObjectState.Delete to all the Bom Detail For Above Bom.
                foreach (BomDetail item in bomdetail)
                {
                    _BomDetailService.Delete(item.BomDetailId);
                }


                var temp = (from L in db.BomDetail
                            where L.ProductId == vm.id
                            select new { BomDetailId = L.BomDetailId }).ToList();


                foreach (var item in temp)
                {
                    _BomDetailService.Delete(item.BomDetailId);
                }

                // Now delete the Parent Bom
                _ProductService.Delete(product);


                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }
                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                Product product = _ProductService.Find(vm.id);

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = product,
                });


                IEnumerable <BomDetail> bomdetail = _BomDetailService.GetBomDetailList(vm.id);
                //Mark ObjectState.Delete to all the Bom Detail For Above Bom.
                foreach (BomDetail item in bomdetail)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item,
                    });
                    _BomDetailService.Delete(item.BomDetailId);
                }


                var temp = (from L in db.BomDetail
                            where L.ProductId == vm.id
                            select new { BomDetailId = L.BomDetailId }).ToList();


                foreach (var item in temp)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item,
                    });

                    _BomDetailService.Delete(item.BomDetailId);
                }

                // Now delete the Parent Bom
                _ProductService.Delete(product);
                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.DesignConsumption).DocumentTypeId,
                    DocId           = product.ProductId,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    xEModifications = Modifications,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }