Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("ClientCode,Name,ClientTypeID,Building,Address,Phone,Fax,Email")] ClientCreateVM cvm)
        {
            if (ModelState.IsValid)
            {
                ClientModel clientMasterModels = new ClientModel
                {
                    ClientCode   = cvm.ClientCode,
                    Name         = cvm.Name,
                    ClientTypeID = cvm.ClientTypeID,
                    Building     = cvm.Building,
                    Address      = cvm.Address,
                    Phone        = cvm.Phone,
                    Fax          = cvm.Fax,
                    Email        = cvm.Email
                };
                //clientMasterModels = cvm;
                _context.Add(clientMasterModels);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.ClientTypeList = _context.ClientTypeModel.ToList().Select(u => new SelectListItem
            {
                Text  = u.Name,
                Value = u.ID.ToString()
            });

            return(View(cvm));
        }
Ejemplo n.º 2
0
        // add a client
        public bool AddClient(ClientCreateVM client, out string msg)
        {
            // check if a client with same name exists
            Client c = _context.Client.Where(a => a.ClientName == client.ClientName)
                       .FirstOrDefault();

            if (c != null)
            {
                msg = "Client name already exist.";
                return(false);
            }
            try
            {
                Client newClient = new Client()
                {
                    ClientName  = client.ClientName,
                    StatusID    = client.StatusID,
                    ReferenceID = Guid.NewGuid().ToString()
                };
                _context.Client.Add(newClient);
                _context.SaveChanges();
                msg = "Client successfully added";
                return(true);
            }
            catch
            {
                msg = "Failed to add client.";
                return(false);
            }
        }
Ejemplo n.º 3
0
        public IActionResult Create(ClientCreateVM model)
        {
            model.Countries   = new SelectList(GetCountries(), "CountryId", "Name");
            model.ClientTypes = new SelectList(GetClientTypes(), "ClientTypeId", "Name");

            if (!ModelState.IsValid)
            {
                Response.StatusCode = 400;
                return(PartialView("_Create", model));
            }
            try
            {
                Client client = new Client();
                client.CopyObject(model);
                var userId = _userManager.GetUserId(HttpContext.User);

                client.UserId = userId;

                _context.Clients.Add(client);
                _context.SaveChanges();

                _ajaxFlashMessage.Success("Client created");
                return(PartialView("_Create", model));
            }
            catch (Exception ex)
            {
                return(PartialView("Error"));
            }
        }
        public ActionResult Create()
        {
            var model = new ClientCreateVM
            {
                StatusList = _sRepo.GetStatusList(Key.ROLE_CLIENT)
            };

            return(View(model));
        }
Ejemplo n.º 5
0
        public IActionResult Create()
        {
            ClientCreateVM model = new ClientCreateVM
            {
                Countries   = new SelectList(GetCountries(), "CountryId", "Name"),
                ClientTypes = new SelectList(GetClientTypes(), "ClientTypeId", "Name")
            };

            return(PartialView("_Create", model));
        }
        public ActionResult Create(ClientCreateVM model)
        {
            string msg = "";

            if (ModelState.IsValid)
            {
                bool success = _cRepo.AddClient(model, out msg);
                if (success)
                {
                    TempData["SuccessMsg"] = msg;
                    return(RedirectToAction("index"));
                }
                else
                {
                    TempData["ErrorMsg"] = msg;
                }
            }
            else
            {
                TempData["ErrorMsg"] = "Client cannot be added at this time.";
            }
            model.StatusList = _sRepo.GetStatusList(Key.ROLE_CLIENT);
            return(View(model));
        }