public void Save(OutletTypeViewModel outletTypeViewModel)
 {
     
     OutletType outletType = new OutletType(outletTypeViewModel.Id)
     {
         Name = outletTypeViewModel.Name,
         Code=outletTypeViewModel.code
     };
     _outletTypeRepository.Save(outletType);
 }
Ejemplo n.º 2
0
 public ActionResult EditOutletType(OutletTypeViewModel vm)
 {
     try
     {
         _outletTypeViewModelBuilders.Save(vm);
         return RedirectToAction("listoutlettypes");
     }
     catch (DomainValidationException ve)
     {
         ValidationSummary.DomainValidationErrors(ve, ModelState);
         return View();
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
         return View();
     }
 }
Ejemplo n.º 3
0
        public ActionResult CreateOutletType(OutletTypeViewModel outletTypeViewModel)
        {
            try
            {
                string Create = Request.Params["Create"];
                string process = Request.Params["process"];
                _outletTypeViewModelBuilders.Save(outletTypeViewModel);
                return RedirectToAction("listoutlettypes");
            }
            catch (DomainValidationException ve)
            {
                ValidationSummary.DomainValidationErrors(ve, ModelState);
                return View(outletTypeViewModel);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return View(outletTypeViewModel);
            }

        }
Ejemplo n.º 4
0
        public ActionResult ImportOutletType(HttpPostedFileBase file)
        {

            try
            {

                var fileName = Path.GetFileName(file.FileName);


                var directory = Server.MapPath("~/Uploads");
                if (Directory.Exists(directory) == false)
                {
                    Directory.CreateDirectory(directory);
                }
                var path = Server.MapPath("~/Uploads") + "\\" + fileName;


                file.SaveAs(path);


                string fileExtension = Path.GetExtension(fileName);
                if (fileExtension == ".xlsx")
                {
                    ViewBag.msg = "Please wait. Upload in progress";

                    string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;HDR=YES;'";

                    OleDbConnection conn = new OleDbConnection(connectionString);
                    try
                    {
                        conn.Open();
                        OleDbCommand command = new OleDbCommand("SELECT code,name FROM [Sheet1$]", conn);
                        OleDbDataReader reader = command.ExecuteReader();
                        OutletTypeViewModel pdvm = new OutletTypeViewModel();
                        while (reader.Read())
                        {

                            string code = reader["code"].ToString();
                            string name = reader["name"].ToString();

                            bool hasDuplicateName = _outletTypeViewModelBuilders.GetAll()
                            .Any(p => p.Name == name);

                            if (hasDuplicateName)
                            { }
                            else
                            {
                                pdvm.Name = name;
                                pdvm.code = code;

                                _outletTypeViewModelBuilders.Save(pdvm);
                            }
                        }
                    }
                    catch (OleDbException ex)
                    {
                        ViewBag.msg = ex.ToString();
                        return View();
                    }

                    finally
                    {
                        conn.Close();

                    }

                    fi = new FileInfo(path);

                    fi.Delete();
                    _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Import", "Outlet Type", DateTime.Now);
                    ViewBag.msg = "Upload Successful";
                    return RedirectToAction("ListOutletTypes");
                }

                else
                {
                    fi = new FileInfo(path);

                    fi.Delete();
                    ViewBag.msg = "Please upload excel file with extension .xlsx";
                    return View();
                }
            }
            catch (Exception ex)
            {

                ViewBag.msg = ex.ToString();
                return View();
            }
        }
Ejemplo n.º 5
0
        public ActionResult CreateOutletType(OutletTypeViewModel outletTypeViewModel)
        {
            try
            {
                string Create = Request.Params["Create"];
                string process = Request.Params["process"];
                outletTypeViewModel.Id = Guid.NewGuid();
                _outletTypeViewModelBuilders.Save(outletTypeViewModel);
                TempData["msg"] = "Outlet Type Successfully Created";
                _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Outlet Type", DateTime.Now);
                return RedirectToAction("listoutlettypes");
            }
            catch (DomainValidationException ve)
            {
                ValidationSummary.DomainValidationErrors(ve, ModelState);
                _log.Debug("Failed to create outlet type  " + ve.Message);
                _log.Error("Failed to create outlet type " + ve.ToString());
                return View(outletTypeViewModel);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                _log.Debug("Failed to create outlet type  " + ex.Message);
                _log.Error("Failed to create outlet type " + ex.ToString());
                return View(outletTypeViewModel);
            }

        }
Ejemplo n.º 6
0
 public ActionResult EditOutletType(OutletTypeViewModel vm)
 {
     try
     {
         _outletTypeViewModelBuilders.Save(vm);
         TempData["msg"] = "Outlet Type Successfully Edited";
         _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Edit", "Outlet Type", DateTime.Now);
         return RedirectToAction("listoutlettypes");
     }
     catch (DomainValidationException ve)
     {
         ValidationSummary.DomainValidationErrors(ve, ModelState);
         _log.Debug("Failed to edit outlet type  " + ve.Message);
         _log.Error("Failed to edit outlet type " + ve.ToString());
         return View();
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
         _log.Debug("Failed to edit outlet type  " + ex.Message);
         _log.Error("Failed to edit outlet type " + ex.ToString());
         return View();
     }
 }