Пример #1
0
 public Company_form()
 {
     InitializeComponent();
     Title = "Création d'une nouvelle entreprise";
     companyFormViewModel = new CompanyFormViewModel();
     DataContext          = companyFormViewModel;
 }
Пример #2
0
        public ViewResult New()
        {
            //12.29.17 - BTo - Needed. Otherwise View will return a Model.IsValid = false
            var viewModel = new CompanyFormViewModel();

            viewModel.CompanyId = 0;
            viewModel.Tasks     = _context.Tasks.ToList();

            return(View("CompanyForm", viewModel));
        }
Пример #3
0
        public ActionResult Edit(int id)
        {
            var viewModel = new CompanyFormViewModel(_context.Companies.SingleOrDefault(m => m.CompanyId == id));

            viewModel.Tasks = _context.Tasks.ToList();

            if (viewModel == null)
            {
                return(HttpNotFound());
            }

            return(View("CompanyForm", viewModel));
        }
Пример #4
0
        // GET: Admin/Customer/Edit/5
        public ActionResult Edit()
        {
            string userName = HttpContext.User.Identity.Name;
            var    user     = UserManager.FindByName(userName);

            var company = companyService.GetCompany(user.CompanyId);
            CompanyFormViewModel editCompany = Mapper.Map <Company, CompanyFormViewModel>(company);

            if (company == null)
            {
                return(HttpNotFound());
            }

            return(View(editCompany));
        }
Пример #5
0
        public ActionResult CreateCompany(CompanyFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView());
            }

            var newCompany = new Company();

            newCompany.Name = model.Name;

            companyService.Add(newCompany);

            return(Json(new { success = true }));
        }
Пример #6
0
        public ActionResult EditCompany(CompanyFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            var companyToEdit = companyService.GetById(model.Id.Value);

            companyToEdit.Name = model.Name;

            companyService.Update(companyToEdit);

            return(Json(new { success = true }));
        }
Пример #7
0
        // GET: Company/New
        public ActionResult New()
        {
            var states     = _context.states.ToList();
            var cities     = _context.cities.ToList();
            var categories = _context.categories.ToList();

            var viewModel = new CompanyFormViewModel
            {
                states     = states,
                cities     = cities,
                categories = categories
            };

            return(View("CompanyForm", viewModel));
        }
Пример #8
0
        public ActionResult Edit(CompanyFormViewModel editCompany)
        {
            Company company = Mapper.Map <CompanyFormViewModel, Company>(editCompany);

            if (ModelState.IsValid)
            {
                companyService.UpdateCompany(company);
                TempData.Add("flash", new FlashSuccessViewModel("Your company details have been saved successfully."));
                return(RedirectToAction("Details", new { id = company.Id }));
            }
            else
            {
                TempData.Add("flash", new FlashDangerViewModel("There was an error saving your company details"));
            }
            return(View(editCompany));
        }
Пример #9
0
        public ActionResult Save(CompanyFormViewModel companyViewModel)
        {
            Companies    company   = new Companies();
            CompanyTasks compTasks = new CompanyTasks();

            if (!ModelState.IsValid)
            {
                return(View("CompanyForm"));
            }

            if (companyViewModel.CompanyId == 0)
            {
                //add company
                company.CompanyName = companyViewModel.CompanyName;
                company.Email       = companyViewModel.Email;
                company.Phone       = companyViewModel.Phone;

                _context.Companies.Add(company);
                _context.SaveChanges(); //save to get the new company id

                //add company tasks
                PrepareTemplate autoInsertTask = new PrepareTemplate();
                var             total          = System.Web.HttpContext.Current.Request.Params["totalTasks"];
                for (var i = 1; i <= Convert.ToInt32(total); i++)
                {
                    compTasks.CompanyId = company.CompanyId;
                    compTasks.TaskId    = Convert.ToInt32(System.Web.HttpContext.Current.Request.Params["TaskId" + i.ToString()]);

                    //auto insert tasks
                    autoInsertTask.InsertTemplateForCompany(compTasks.TaskId, compTasks.CompanyId);
                }

                _context.CompanyTasks.Add(compTasks);
            }
            else
            {
                var companyInDb = _context.Companies.Single(c => c.CompanyId == company.CompanyId);
                companyInDb.CompanyName = company.CompanyName;
                companyInDb.Email       = company.Email;
                companyInDb.Phone       = company.Phone;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Companies"));
        }
Пример #10
0
        // GET: Company/Edit
        public ActionResult Edit(int id)
        {
            var company = _context.companies.SingleOrDefault(c => c.ID == id);

            if (company == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new CompanyFormViewModel
            {
                company    = company,
                states     = _context.states.ToList(),
                cities     = _context.cities.ToList(),
                categories = _context.categories.ToList()
            };

            return(View("CompanyForm", viewModel));
        }
Пример #11
0
        public Company_form(long ID)
        {
            InitializeComponent();
            CompanyID = ID;
            Title     = "Modification d'une entreprise";

            try
            {
                ModelCRMTest m       = new ModelCRMTest();
                Company      company = m.Company.Where(x => x.ID == ID).First();
                companyFormViewModel = new CompanyFormViewModel(company);
                DataContext          = companyFormViewModel;
            }
            catch
            {
                MessageBox.Show("L'entreprise n'a pas été trouvée.", "Erreur", MessageBoxButton.OK, MessageBoxImage.Stop);
                Close();
            }
        }
Пример #12
0
        public ActionResult CreateCompany(CompanyFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var company = Mapper.Map <CompanyFormViewModel, Company>(viewModel);

            try
            {
                companyRepository.AddCompany(company);

                unitOfWork.Save();
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception)
            {
                return(View("CompanyForm"));
            }
        }
Пример #13
0
        // GET: Admin/Customer/Create
        public ActionResult Create()
        {
            var createCompany = new CompanyFormViewModel();

            return(View(createCompany));
        }
        public ActionResult Details(CompanyFormViewModel model, OptionsViewModel moreInfo) //, System.Web.HttpPostedFileBase upload
        {
            List <Error> errors = new List <Error>();

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    errors = _hrUnitOfWork.CompanyRepository.CheckForm(new CheckParm
                    {
                        CompanyId  = CompanyId,
                        ObjectName = "Company",
                        TableName  = "Companies",
                        Columns    = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))),
                        Culture    = Language
                    });

                    if (errors.Count() > 0)
                    {
                        foreach (var e in errors)
                        {
                            foreach (var errorMsg in e.errors)
                            {
                                ModelState.AddModelError(errorMsg.field, errorMsg.message);
                            }
                        }

                        return(Json(Models.Utils.ParseFormErrors(ModelState)));
                    }
                }
            }
            else
            {
                return(Json(Models.Utils.ParseFormErrors(ModelState)));
            }

            Model.Domain.Company record;
            //var Sequence = _hrUnitOfWork.Repository<Model.Domain.Company>().Select(a => a.Code).DefaultIfEmpty(0).Max();
            //var MaxCode = Sequence == 0 ? 1 : Sequence + 1;
            var edit = Request.QueryString["edit"];

            if (model.Id == -1) // New
            {
                record = new Model.Domain.Company();
                AutoMapper(new Models.AutoMapperParm
                {
                    Destination = record,
                    Source      = model,
                    ObjectName  = "Company",
                    Options     = moreInfo,
                    Transtype   = TransType.Insert
                });
                record.CreatedUser = UserName;
                record.CreatedTime = DateTime.Now;
                // record.Code = MaxCode;
                _hrUnitOfWork.CompanyRepository.AddLName(Language, record.Name, model.Name, model.LocalName);
                _hrUnitOfWork.PagesRepository.AddCompany(record);
            }

            else // Edit
            {
                record = _hrUnitOfWork.Repository <Model.Domain.Company>().FirstOrDefault(a => a.Id == model.Id);
                AutoMapper(new Models.AutoMapperParm
                {
                    Destination = record,
                    Source      = model,
                    ObjectName  = "Company",
                    Options     = moreInfo,
                    Transtype   = TransType.Update
                });
                record.ModifiedTime = DateTime.Now;
                record.ModifiedUser = UserName;
                _hrUnitOfWork.CompanyRepository.AddLName(Language, record.Name, model.Name, model.LocalName);
                _hrUnitOfWork.CompanyRepository.Attach(record);
                _hrUnitOfWork.CompanyRepository.Entry(record).State = EntityState.Modified;
            }

            try
            {
                _hrUnitOfWork.Save();
            }
            catch (Exception ex)
            {
                var msg = _hrUnitOfWork.HandleDbExceptions(ex, Language);
                if (msg.Length > 0)
                {
                    return(Json(msg));
                }
            }

            var    savedCompany = _hrUnitOfWork.Repository <Model.Domain.Company>().FirstOrDefault(c => c.Name == model.Name);
            string message      = "OK," + (new JavaScriptSerializer().Serialize(savedCompany));

            return(Json(message));
        }
Пример #15
0
        public ActionResult CreateCompany(string userId)
        {
            var viewModel = new CompanyFormViewModel(userId);

            return(View("CompanyForm", viewModel));
        }
Пример #16
0
 public CompanyFormView()
 {
     InitializeComponent();
     _vm         = new CompanyFormViewModel(new Company());
     DataContext = _vm;
 }
Пример #17
0
        public IActionResult CreateCompany(CompanyFormViewModel model)
        {
            if (!ModelState.IsValid)
                return PartialView(model);

            var newCompany = new Company();

            newCompany.Name = model.Name;

            companyService.Add(newCompany);

            return Json(new { success = true });
        }
Пример #18
0
        public IActionResult EditCompany(CompanyFormViewModel model)
        {
            if (!ModelState.IsValid)
                return PartialView(model);
            
            var companyToEdit = companyService.GetById(model.Id.Value);

            companyToEdit.Name = model.Name;

            companyService.Update(companyToEdit);

            return Json(new { success = true });
        }