コード例 #1
0
        public async Task <string> CreateSubmit([FromBody] CreateProjectSubmitVm model)
        {
            //var roles = this.roleManager.Roles.ToList();
            var rolesUser = new Roles(this.roleManager, this.userManager);


            var allUsers = dbContext.ListUsers.Include(u => u.AccountUser).ToList();
            ////var curentuser = allUsers.FirstOrDefault(u => u.AccountUser.Email == userName);
            //var addedRoles = roles.Except(roles).ToList();

            string userRole = "";

            if (!string.IsNullOrEmpty(model.UserName))
            {
                var curentuser = allUsers.FirstOrDefault(u => u.AccountUser.Email == model.UserName);

                if (curentuser != null)
                {
                    userRole = rolesUser.GetRole(curentuser.AccountUser);
                }

                var newProduct = new Project()
                {
                    Id = Guid.NewGuid(),
                };

                if (!string.IsNullOrEmpty(model.Title) && !string.IsNullOrEmpty(model.Description) &&
                    model.TypeId != default)
                {
                    var type = this.dbContext.Types.FirstOrDefault(t => t.Id == model.TypeId);

                    newProduct.Title = model.Title;

                    newProduct.Description  = model.Description;
                    newProduct.Organization = model.Organization;
                    newProduct.Role         = userRole;
                    newProduct.Link         = model.Link;

                    newProduct.ProjectTypeId = type.Id;

                    newProduct.Created = DateTime.Now;
                    newProduct.Updated = DateTime.Now;



                    dbContext.Projects.Add(newProduct);
                    await dbContext.SaveChangesAsync();


                    return("The project was successfully created");
                }
                else
                {
                    return("Title, Description, Role, Type - must be filled");
                }
            }
            return("UserName - must be filled");
        }
コード例 #2
0
ファイル: ProjectController.cs プロジェクト: Osyny/Erp_TEST
        public IActionResult Create()
        {
            var allTypes = this.dbContext.Types.ToList();

            var model = new CreateProjectSubmitVm()
            {
                Types = allTypes.Select(t => new SelectListItem
                {
                    Value = t.Id.ToString(),
                    Text  = t.NameType
                }).ToList()
            };

            return(View("/Views/Projects/Create.cshtml", model));
        }
コード例 #3
0
ファイル: ProjectController.cs プロジェクト: Osyny/Erp_TEST
        public async Task <IActionResult> Create(CreateProjectSubmitVm model)
        {
            var roles = this.roleManager.Roles.ToList();

            var userName  = HttpContext.User.Identity.Name;
            var rolesUser = new Roles(this.roleManager, this.userManager);

            var allUsers   = dbContext.ListUsers.Include(u => u.AccountUser).ToList();
            var curentuser = allUsers.FirstOrDefault(u => u.AccountUser.Email == userName);
            //var addedRoles = roles.Except(roles).ToList();


            string userRole = "";

            if (!string.IsNullOrEmpty(userName))
            {
                if (curentuser != null)
                {
                    userRole = rolesUser.GetRole(curentuser.AccountUser);
                }

                var type = this.dbContext.Types.FirstOrDefault(t => t.Id == model.TypeId);


                var newProduct = new Project()
                {
                    Id = Guid.NewGuid(),
                };

                if (ModelState.IsValid)
                {
                    newProduct.Title = model.Title;

                    newProduct.Description  = model.Description;
                    newProduct.Organization = model.Organization;
                    newProduct.Role         = userRole;
                    newProduct.Link         = model.Link;

                    newProduct.ProjectTypeId = type.Id;

                    newProduct.Created = DateTime.Now;
                    newProduct.Updated = DateTime.Now;



                    dbContext.Projects.Add(newProduct);
                    await dbContext.SaveChangesAsync();


                    //return RedirectToAction(nameof(UploadFile), new { prId = newProduct.Id });
                    return(RedirectToAction(nameof(EditProject), new { Id = newProduct.Id }));
                }
                else
                {
                    var allTypes = this.dbContext.Types.ToList();
                    model.Types = allTypes.Select(t => new SelectListItem
                    {
                        Value = t.Id.ToString(),
                        Text  = t.NameType
                    }).ToList();
                    ModelState.AddModelError("", "Title, Description, Type - must be filled");
                }
            }
            return(View("/Views/Projects/Create.cshtml", model));
        }