public ActionResult ProductCustomGroupExcelImport()
        {
            var    file     = Request.Files[0];
            string filePath = Request.MapPath(ConfigurationManager.AppSettings["ExcelFilePath"] + file.FileName);

            file.SaveAs(filePath);
            var excel = new ExcelQueryFactory();

            //excel.FileName =ConfigurationManager.AppSettings["ExcelFilePath"]; //  @"C:\Users\guru\Downloads\PO.xls"; //TODO: Rempve hardcode
            excel.FileName = filePath;
            var ProductCustomGroupRecordList = from c in excel.Worksheet <ProductCustomGroupExcelViewModel>() select c;

            StringBuilder strProduct = new StringBuilder();

            foreach (var ProductCustomGroupRecord in ProductCustomGroupRecordList)
            {
                if (_ProductService.Find(ProductCustomGroupRecord.ProductName) == null)
                {
                    if (!strProduct.ToString().Contains("" + ProductCustomGroupRecord.ProductName))
                    {
                        strProduct.Append(" " + ProductCustomGroupRecord.ProductName + ",");
                    }
                }
            }
            if (!string.IsNullOrEmpty(strProduct.ToString()))
            {
                if (string.IsNullOrEmpty(strProduct.ToString()))
                {
                    ViewBag.product = null;
                }
                else
                {
                    ViewBag.product = strProduct;
                }
                return(View());
            }
            else
            {
                string previousRecord          = null;
                int    count                   = 0;
                ProductCustomGroupHeader stemp = new ProductCustomGroupHeader();
                foreach (var ProductCustomGroupRecord in ProductCustomGroupRecordList)
                {
                    if (count == 0 || ProductCustomGroupRecord.ProductCustomGroupName != previousRecord)
                    {
                        ProductCustomGroupHeader s = new ProductCustomGroupHeader();
                        s.ProductCustomGroupName = ProductCustomGroupRecord.ProductCustomGroupName;
                        s.IsActive     = true;
                        s.CreatedDate  = DateTime.Now;
                        s.ModifiedDate = DateTime.Now;
                        s.CreatedBy    = User.Identity.Name;
                        s.ModifiedBy   = User.Identity.Name;

                        _ProductCustomGroupHeaderService.Create(s);
                        stemp = s;
                    }

                    //Object for ProductCustomGroupLineDetail Model to Save Rate, Quantity, Product

                    Product product           = _ProductService.Find(ProductCustomGroupRecord.ProductName);
                    ProductCustomGroupLine sl = new ProductCustomGroupLine();
                    sl.ProductCustomGroupHeaderId = stemp.ProductCustomGroupId;
                    sl.ProductId    = product.ProductId;
                    sl.Qty          = ProductCustomGroupRecord.Qty;
                    sl.CreatedDate  = DateTime.Now;
                    sl.ModifiedDate = DateTime.Now;
                    sl.CreatedBy    = User.Identity.Name;
                    sl.ModifiedBy   = User.Identity.Name;



                    _ProductCustomGroupLineService.Create(sl);

                    count++;
                    previousRecord = ProductCustomGroupRecord.ProductCustomGroupName;

                    _unitOfWork.Save();
                }

                return(View("Sucess"));
            }
        }
Beispiel #2
0
        public ActionResult HeaderPost(ProductCustomGroupHeader svm)
        {
            if (ModelState.IsValid)
            {
                if (svm.ProductCustomGroupId == 0)
                {
                    svm.CreatedDate  = DateTime.Now;
                    svm.ModifiedDate = DateTime.Now;
                    svm.CreatedBy    = User.Identity.Name;
                    svm.ModifiedBy   = User.Identity.Name;
                    _ProductCustomGroupHeaderService.Create(svm);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", svm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductCustomGroup).DocumentTypeId,
                        DocId        = svm.ProductCustomGroupId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    //return RedirectToAction("Create", "SaleOrderLine", new { Id = s.ProductCustomGroupHeaderId }).Success("Data saved successfully");
                    return(RedirectToAction("Edit", new { id = svm.ProductCustomGroupId }).Success("Data saved Successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductCustomGroupHeader temp = _ProductCustomGroupHeaderService.Find(svm.ProductCustomGroupId);

                    ProductCustomGroupHeader ExRec = Mapper.Map <ProductCustomGroupHeader>(temp);

                    temp.ProductCustomGroupName = svm.ProductCustomGroupName;
                    temp.IsActive     = svm.IsActive;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    _ProductCustomGroupHeaderService.Update(temp);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = temp,
                    });
                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", svm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductCustomGroup).DocumentTypeId,
                        DocId           = temp.ProductCustomGroupId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", svm));
        }