Ejemplo n.º 1
0
        public async Task CreateAsync(CreateProjectInputModel inputModel, int userId)
        {
            var project = new Project()
            {
                AddedOn     = DateTime.UtcNow,
                Name        = inputModel.Name,
                Description = inputModel.Description,
            };

            project.Team = new Team
            {
                AddedOn = DateTime.UtcNow,
                Name    = project.Name + " Team"
            };

            project.Team.TeamsUsers.Add(new TeamsUsers()
            {
                UserId = userId,
                TeamId = project.Team.Id,
            });

            await AddDefaultKanbanBoardToProjectAsync(project);

            await this.projectRepo.AddAsync(project);

            await projectRepo.SaveChangesAsync();
        }
        public async Task <IActionResult> EditProject(string id)
        {
            ViewBag.userMenu = GetMenu();

            if (id == null)
            {
                return(NotFound());
            }
            if (!checkuser())
            {
                return(RedirectToAction("Index", "Home"));
            }

            var Project = await context.Project.SingleOrDefaultAsync(m => m.ProjectNumber == id);

            var e = new CreateProjectInputModel()
            {
                ProjectNumber  = Project.ProjectNumber,
                ProjectId      = Project.ProjectId,
                ProjectName    = Project.ProjectName,
                ProjectManager = Project.ProjectManager,
                ProjectCost    = Project.ProjectCost,
                ProjectStart   = Project.ProjectStart,
                ProjectEnd     = Project.ProjectEnd,
                CustomerTel    = Project.CustomerTel,
                CustomerName   = Project.CustomerName
            };

            ViewData["UserSSPM"] = new SelectList(context.UserSspm.Join(context.UserAssignGroup,
                                                                        u => u.UserId,
                                                                        ua => ua.UserId,
                                                                        (u, ua) => new {
                UserId    = u.UserId,
                Firstname = u.Firstname,
                GroupId   = ua.GroupId,
                Status    = u.Status
            }).Where(ua => ua.GroupId.Equals("50") && ua.Status.Equals("A"))

                                                  , "UserId", "Firstname");
            ViewData["naemproject"] = Project.ProjectName;

            if (Project == null)
            {
                return(NotFound());
            }
            return(PartialView("EditProject", e));
        }
        public async Task <IActionResult> EditProject(string id, CreateProjectInputModel editModel)
        {
            var loggedInUser     = HttpContext.User;
            var loggedInUserName = loggedInUser.Identity.Name;

            ViewBag.userMenu = GetMenu();


            var query = (from x in context.Project where x.ProjectNumber.Equals(editModel.ProjectNumber) select x).FirstOrDefault();

            if (editModel.ProjectNumber != query.ProjectNumber)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //context.Update(ord);
                    var addquery = from test in context.Project
                                   where test.ProjectNumber.Equals(editModel.ProjectNumber)
                                   select test;
                    foreach (Project UserUpdate in addquery)
                    {
                        UserUpdate.ProjectId       = editModel.ProjectId;
                        UserUpdate.ProjectName     = editModel.ProjectName;
                        UserUpdate.ProjectStart    = editModel.ProjectStart;
                        UserUpdate.ProjectEnd      = editModel.ProjectEnd;
                        UserUpdate.ProjectManager  = editModel.ProjectManager;
                        UserUpdate.ProjectEditBy   = loggedInUserName;
                        UserUpdate.ProjectEditDate = DateTime.Now;
                        UserUpdate.ProjectCost     = editModel.ProjectCost;
                        UserUpdate.CustomerName    = editModel.CustomerName;
                        UserUpdate.CustomerTel     = editModel.CustomerTel;
                    }
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(query.ProjectNumber));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create(CreateProjectInputModel createInputModel, PaginationFilter paginationFilter)
        {
            bool   isValid;
            string responseHtml;

            if (!ModelState.IsValid)
            {
                isValid      = false;
                responseHtml = await this.RenderViewAsStringAsync("Create", createInputModel, true);

                return(Json(new { isValid = isValid, html = responseHtml }));
            }

            if (this.projectsService.IsNameTaken(createInputModel.Name))
            {
                ModelState.AddModelError(string.Empty, $"The project '{createInputModel.Name}' already exists.");
                isValid      = false;
                responseHtml = await this.RenderViewAsStringAsync("Create", createInputModel, true);

                return(Json(new { isValid = isValid, html = responseHtml }));
            }

            try
            {
                var userId = int.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);
                await this.projectsService.CreateAsync(createInputModel, userId);

                var responseModel = this.mapper.Map <PaginatedProjectViewModel>
                                        (await this.projectsService.GetAllAsync(userId, paginationFilter));

                isValid      = true;
                responseHtml = await this.RenderViewAsStringAsync("_ViewAll", responseModel, false);
            }
            catch (Exception)
            {
                ModelState.AddModelError(string.Empty, ErrorConstants.ContactSupportMessage);
                isValid      = false;
                responseHtml = await this.RenderViewAsStringAsync("Create", createInputModel, true);
            }

            return(Json(new { isValid = isValid, html = responseHtml }));
        }
        public async Task <IActionResult> CreateProject(CreateProjectInputModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            ViewBag.userMenu = GetMenu();
            if (inputModel.ProjectEnd < inputModel.ProjectStart)
            {
                ModelState.AddModelError("ErrorCreatePtoject", "Estimate Date is incorrect. Please Re Input");
                return(View());
            }
            try
            {
                var loggedInUser     = HttpContext.User;
                var loggedInUserName = loggedInUser.Identity.Name;

                var id = (from u in context.RunningNumber where u.Type.Equals("ProjectNumber") select u).FirstOrDefault();

                int num;
                if (id.Number == null)
                {
                    num = 100001;
                }
                else
                {
                    num = Convert.ToInt32(id.Number);
                    num = num + 1;
                }

                Project ord = new Project
                {
                    ProjectNumber     = num.ToString(),
                    ProjectId         = inputModel.ProjectId,
                    ProjectName       = inputModel.ProjectName,
                    ProjectStart      = inputModel.ProjectStart,
                    ProjectEnd        = inputModel.ProjectEnd,
                    ProjectCost       = inputModel.ProjectCost,
                    ProjectManager    = inputModel.ProjectManager,
                    ProjectCreateBy   = loggedInUserName,
                    ProjectCreateDate = DateTime.Now,
                    CustomerName      = inputModel.CustomerName,
                    CustomerTel       = inputModel.CustomerTel,
                    Note = inputModel.Note
                };


                // Add the new object to the Orders collection.
                context.Project.Add(ord);
                await context.SaveChangesAsync();


                var query = from xx in context.RunningNumber
                            where xx.Type.Equals("ProjectNumber")
                            select xx;

                foreach (RunningNumber RunUserID in query)
                {
                    RunUserID.Number = num.ToString();
                }

                // Submit the changes to the database.
                try
                {
                    await context.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    // Provide for exceptions.
                }

                return(RedirectToAction("Index", "ProjectManagement"));
            }
            catch (Exception ex)
            {
                var message = ex.Message;
                return(View());
            }
        }