Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Employee_Id,Project_Id,Client_Id,Date,NoteNumber,NoteValue,Description,File,Status")] Outlays outlays, IFormFile Document, int?status, int?clients, int?projects, int?employees, int?month, int?year)
        {
            GetSessions();

            if (ViewBag.Email == null)
            {
                return(ExpiredSession());
            }

            if (id != outlays.Id)
            {
                return(NotFound());
            }

            try
            {
                if (ModelState.IsValid)
                {
                    if (Document != null)
                    {
                        string nomeArquivo = string.Concat(id, "-", Document.FileName);
                        _files.EnviarArquivo(Document, nomeArquivo, storage);
                    }

                    _context.Update(outlays);
                    await _context.SaveChangesAsync();
                }
            }
            catch (DbUpdateConcurrencyException e)
            {
                if (!OutlaysExists(outlays.Id))
                {
                    return(NotFound());
                }
                else
                {
                    return(RedirectToAction(nameof(Error), new { message = e.Message }));
                }
            }

            catch (DbConcurrencyException e)
            {
                if (!OutlaysExists(outlays.Id))
                {
                    return(NotFound());
                }
                else
                {
                    return(RedirectToAction(nameof(Error), new { message = e.Message }));
                }
            }

            catch (Exception e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }

            return(RedirectToAction(nameof(Index), new { id, status, clients, projects, employees, month, year }));
            //return View(outlays);
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,Employee_Id,Project_Id,Client_Id,Date,NoteNumber,NoteValue,Description,File,Status")] Outlays outlays, IFormFile Document, int?status, int?clients, int?projects, int?employees, int?month, int?year)
        {
            GetSessions();

            if (ViewBag.Email == null)
            {
                return(ExpiredSession());
            }

            try
            {
                if (ModelState.IsValid && Document != null)
                {
                    string nameFile = outlays.File;
                    outlays.File = string.Empty;
                    string nomeArquivo = string.Empty;

                    _context.Add(outlays);
                    await _context.SaveChangesAsync();


                    int employeeId = ViewBag.Id;

                    var lastId = (from result in _context.Outlays
                                  where result.Employee_Id == employeeId
                                  orderby result.Id descending
                                  select result).FirstOrDefault();

                    if (lastId != null)
                    {
                        int outlaysId = lastId.Id;
                        nomeArquivo = string.Concat(outlaysId, "-", Document.FileName);
                        _files.EnviarArquivo(Document, nomeArquivo, storage);
                    }

                    outlays.File = nomeArquivo;

                    _context.Update(outlays);
                    await _context.SaveChangesAsync();
                }

                return(RedirectToAction(nameof(Index), new { status, clients, projects, employees, month, year }));
            }
            catch (DbUpdateConcurrencyException e)
            {
                if (!OutlaysExists(outlays.Id))
                {
                    return(NotFound());
                }
                else
                {
                    return(RedirectToAction(nameof(Error), new { message = e.Message }));
                }
            }

            catch (DbConcurrencyException e)
            {
                if (!OutlaysExists(outlays.Id))
                {
                    return(NotFound());
                }
                else
                {
                    return(RedirectToAction(nameof(Error), new { message = e.Message }));
                }
            }

            catch (Exception e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }