Example #1
0
        private static void AddContractors(CommerceDbContext context)
        {
            Contractor c = new Contractor();

            c.FirstName         = RandString();
            c.LastName          = RandString();
            c.BankAccountNumber = RandString(15, 15);
            c.City      = RandString();
            c.Country   = RandString();
            c.Email     = RandString() + "@" + RandString(2, 4) + "." + RandString(2, 4);
            c.NBRN      = RandString(15, 15);
            c.Street    = RandString();
            c.TaxNumber = RandString(9, 9);

            context.Add(c);
        }
        public IActionResult Create(Contractor contractor)
        {
            if (ModelState.IsValid)
            {
                dbContext.Add <Contractor>(contractor);
                dbContext.SaveChanges();
                ViewData["Success"] = "Contractor created successfully";
            }
            else
            {
                ViewData["Error"] = "An error occur during creating new contractor";

                string[] errorMessages = ModelState.Values.SelectMany(v => v.Errors).Select(v => v.ErrorMessage).ToArray();

                ViewData["ErrorMessages"] = errorMessages;
            }

            return(View());
        }