public async Task <IActionResult> Create([Bind("Id,Code,Name,ApprovalTypeId,IsActive")] ApprovalHierarchy approvalHierarchy)
        {
            if (ModelState.IsValid)
            {
                _context.Add(approvalHierarchy);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApprovalTypeId"] = new SelectList(_context.ApprovalType, "Id", "Name", approvalHierarchy.ApprovalTypeId);
            return(View(approvalHierarchy));
        }
        public async Task <IActionResult> Create([Bind("Id,ApprovalHierarchyId,UserId,Sequence")] ApprovalHierarchyDetail approvalHierarchyDetail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(approvalHierarchyDetail);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "ApprovalHierarchies"));
            }
            ViewData["approvalHierarchyId"] = new SelectList(_context.ApprovalHierarchy, "Id", "Name", approvalHierarchyDetail.Id);
            ViewData["UserId"] = new SelectList(_context.AspNetUsers, "Id", "UserName", approvalHierarchyDetail.UserId);
            return(View(approvalHierarchyDetail));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,ApprovalId,UserId,Sequence,ApprovalStatusId,ApprovalDate")] ApprovalDetail approvalDetail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(approvalDetail);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApprovalId"]       = new SelectList(_context.Approval, "Id", "Id", approvalDetail.ApprovalId);
            ViewData["ApprovalStatusId"] = new SelectList(_context.ApprovalStatus, "Id", "Id", approvalDetail.ApprovalStatusId);
            ViewData["UserId"]           = new SelectList(_context.AspNetUsers, "Id", "Id", approvalDetail.UserId);
            return(View(approvalDetail));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,Title,Description,ApprovalTypeId,ApprovalStatusId,AssignedTo,CreatedOn,CreatedBy,UpdateOn,UpdateBy,IsDeleted")] Approval approval, IFormFile file)
        {
            var path = "";

            if (file != null && file.Length > 0)
            {
                path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Docs",
                                    file.FileName);
                var filePath = Path.GetTempFileName();

                //using (var stream = System.IO.File.Create(filePath))
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    if (stream.Length < 2097152)
                    {
                        await file.CopyToAsync(stream);
                    }
                }
            }
            if (ModelState.IsValid)
            {
                var hierarachy      = _context.ApprovalHierarchy.SingleOrDefault(t => t.ApprovalTypeId == approval.ApprovalTypeId);
                var hierarchyDetail = _context.ApprovalHierarchyDetail.Where(t => t.ApprovalHierarchyId == hierarachy.Id).ToList();
                approval.AssignedTo       = hierarchyDetail.Single(t => t.Sequence == hierarchyDetail.Min(tt => tt.Sequence)).UserId;
                approval.ApprovalStatusId = 1;
                approval.FilePath         = path;

                foreach (var item in hierarchyDetail)
                {
                    ApprovalDetail approvalDetail = new ApprovalDetail()
                    {
                        ApprovalId = approval.Id, UserId = item.UserId, Sequence = item.Sequence, ApprovalStatusId = 1
                    };
                    //_context.Add(approvalDetail);
                    approval.ApprovalDetail.Add(approvalDetail);
                }
                _context.Add(approval);
                var record = await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApprovalStatusId"] = new SelectList(_context.ApprovalStatus, "Id", "Name", approval.ApprovalStatusId);
            ViewData["ApprovalTypeId"]   = new SelectList(_context.ApprovalType, "Id", "Name", approval.ApprovalTypeId);
            ViewData["CreatedBy"]        = new SelectList(_context.AspNetUsers, "Id", "UserName", approval.CreatedBy);
            ViewData["UpdateBy"]         = new SelectList(_context.AspNetUsers, "Id", "UserName", approval.UpdateBy);
            return(View(approval));
        }