public void CreateReturnableProduct(ReturnableProductViewModel retunableVM)
 {
     ReturnableProduct rp = _productRepository.GetById(retunableVM.Id) as ReturnableProduct;
     if (rp==null)
         rp = _productFactory.CreateReturnableProduct(retunableVM.Id);
     rp.Brand = _productBrandRepository.GetById(retunableVM.BrandId);
     rp.ExFactoryPrice = retunableVM.ExFactoryPrice;
     rp.Description = retunableVM.Description;
     rp.Packaging = _productPackagingRepository.GetById(retunableVM.PackagingId);
     rp.PackagingType = _productPackagingTypeRepository.GetById(retunableVM.PackagingTypeId);
     rp.ProductCode = retunableVM.ProductCode;
     rp.Flavour = _productFlavourRepository.GetById(retunableVM.FlavourID);
     // = _productTypeRepository.GetById(pt.Id);
     rp.VATClass = _vatClassRepository.GetById(retunableVM.VatClassId);
     rp.ReturnableType = (ReturnableType)retunableVM.ReturnableType;
     rp.Capacity = retunableVM.Capacity;
     if (retunableVM.ReturnableProductId != null)
         rp.ReturnAbleProduct = _productRepository.GetById(retunableVM.ReturnableProductId.Value) as ReturnableProduct;
     else rp.ReturnAbleProduct = null;
     _productRepository.Save(rp);
     if (retunableVM.Id == Guid.Empty)
     {
         addDefaultPriceForReturnable();
     }
 }
 public ActionResult EditReturnableProduct(ReturnableProductViewModel vm)
 {
     
     try
     {
         _productViewModelBuilder.CreateReturnableProduct(vm);
         _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Edit", "Returnable Product", DateTime.Now);
         TempData["msg"] = "Returnable Product Successfully Edited";
         return RedirectToAction("Index");
     }
     catch (DomainValidationException dve)
     {
         ValidationSummary.DomainValidationErrors(dve, ModelState);
         ViewBag.BrandsList = _productViewModelBuilder.GetBrands();
         ViewBag.PackagingsList = _productViewModelBuilder.GetPackaging();
         ViewBag.PackTypeList = _productViewModelBuilder.GetPackagingType();
         ViewBag.ReturnableTypeList = _productViewModelBuilder.GetReturnableType();                
         ViewBag.FlavoursList = _productViewModelBuilder.GetFlavours();
         ViewBag.VatClassList = _productViewModelBuilder.VatClass();
         ViewBag.RetReturnableProductList = _productViewModelBuilder.GetRetReturnableProducts();                
         _log.ErrorFormat("Error in editing returnable product " + dve.Message);
         _log.InfoFormat("Error in editing returnable product " + dve.Message);
         ViewBag.Title = "Edit Returnable Product";
         ViewBag.msg = dve.Message;
         return View();
     }
     catch (Exception ex)
     {
         ViewBag.msg = ex.Message;
         ViewBag.msg = ex.ToString();
         ViewBag.BrandsList = _productViewModelBuilder.GetBrands();
         ViewBag.PackagingsList = _productViewModelBuilder.GetPackaging();
         ViewBag.PackTypeList = _productViewModelBuilder.GetPackagingType();
         ViewBag.ReturnableTypeList = _productViewModelBuilder.GetReturnableType();
         ViewBag.FlavoursList = _productViewModelBuilder.GetFlavours();
         ViewBag.VatClassList = _productViewModelBuilder.VatClass();
         ViewBag.RetReturnableProductList = _productViewModelBuilder.GetRetReturnableProducts();
         ViewBag.Title = "Edit Returnable Product";
         
         return View();
     }
     //return View(_productViewModelBuilder.CreateEditReturnableProductViewModel(vm.Id));
 }
        public ActionResult EditReturnableProduct(ReturnableProductViewModel vm)
        {

            try
            {
                _productViewModelBuilder.CreateReturnableProduct(vm);
                TempData["msg"] = "Returnable Product Successfully Edited";
                return RedirectToAction("Index");
            }
            catch (DomainValidationException dve)
            {
                ValidationSummary.DomainValidationErrors(dve, ModelState);
                ViewBag.BrandsList = _productViewModelBuilder.GetBrands();
                ViewBag.PackagingsList = _productViewModelBuilder.GetPackaging();
                ViewBag.PackTypeList = _productViewModelBuilder.GetPackagingType();
                ViewBag.ReturnableTypeList = _productViewModelBuilder.GetReturnableType();
                ViewBag.FlavoursList = _productViewModelBuilder.GetFlavours();
                ViewBag.VatClassList = _productViewModelBuilder.VatClass();
                ViewBag.RetReturnableProductList = _productViewModelBuilder.GetRetReturnableProducts();
                ViewBag.Title = "Edit Returnable Product";
                ViewBag.msg = dve.Message;
                return View();
            }
            catch (Exception ex)
            {
                ViewBag.msg = ex.Message;
                ViewBag.msg = ex.ToString();
                ViewBag.BrandsList = _productViewModelBuilder.GetBrands();
                ViewBag.PackagingsList = _productViewModelBuilder.GetPackaging();
                ViewBag.PackTypeList = _productViewModelBuilder.GetPackagingType();
                ViewBag.ReturnableTypeList = _productViewModelBuilder.GetReturnableType();
                ViewBag.FlavoursList = _productViewModelBuilder.GetFlavours();
                ViewBag.VatClassList = _productViewModelBuilder.VatClass();
                ViewBag.RetReturnableProductList = _productViewModelBuilder.GetRetReturnableProducts();
                ViewBag.Title = "Edit Returnable Product";
                
                return View();
            }
           
        }
        public ActionResult CreateReturnableProduct(ReturnableProductViewModel vm)
        {
           
            try
            {
                ViewBag.msg = null;
                vm.Id = Guid.NewGuid();
                _productViewModelBuilder.CreateReturnableProduct(vm);
                _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Edit", "Returnable Product", DateTime.Now);
                TempData["msg"] = "Returnable Product Successfully Created";

                return RedirectToAction("Index");
            }
            catch (DomainValidationException dve)
            {
                ValidationSummary.DomainValidationErrors(dve, ModelState);
                ViewBag.BrandsList = _productViewModelBuilder.GetBrands();
                ViewBag.PackagingsList = _productViewModelBuilder.GetPackaging();
                ViewBag.PackTypeList = _productViewModelBuilder.GetPackagingType();
                ViewBag.ReturnableTypeList = _productViewModelBuilder.GetReturnableType();
                ViewBag.FlavoursList = _productViewModelBuilder.GetFlavours();
                ViewBag.VatClassList = _productViewModelBuilder.VatClass();
                ViewBag.RetReturnableProductList = _productViewModelBuilder.GetRetReturnableProducts();
                _log.ErrorFormat("Error in editing returnable product " + dve.Message);
                _log.InfoFormat("Error in editing returnable product " + dve.Message);
                ViewBag.Title = "Edit Returnable Product";
                
                return View();
            }
            catch (Exception ex)
            {
                ViewBag.msg = ex.Message;
                ViewBag.msg = ex.ToString();
                ViewBag.BrandsList = _productViewModelBuilder.GetBrands();
                ViewBag.PackagingsList = _productViewModelBuilder.GetPackaging();
                ViewBag.PackTypeList = _productViewModelBuilder.GetPackagingType();
                ViewBag.ReturnableTypeList = _productViewModelBuilder.GetReturnableType();
                ViewBag.FlavoursList = _productViewModelBuilder.GetFlavours();
                ViewBag.VatClassList = _productViewModelBuilder.VatClass();
                ViewBag.RetReturnableProductList = _productViewModelBuilder.GetRetReturnableProducts();
                ViewBag.Title = "Edit Returnable Product";
                try
                {
                    HQMailerViewModelBuilder hqm = new HQMailerViewModelBuilder(ConfigurationSettings.AppSettings["ServerIP"], ConfigurationSettings.AppSettings["UserName"], ConfigurationSettings.AppSettings["Password"]);


                    hqm.Send(ConfigurationSettings.AppSettings["ServerEmail"], ConfigurationSettings.AppSettings["MailGroup"], "Test", "editing sale product error:" + ex.Message);
                }
                catch (Exception exx)
                { }
                return View(vm);
            }
            
        }