Ejemplo n.º 1
0
        public async Task <ActionResult <ErrWrs> > EditErrWrs(int id, [FromForm] IFormFile plans, [FromForm] string error)
        {
            var errwrs = JsonConvert.DeserializeObject <ErrWrs>(error);

            if (id != errwrs.Id)
            {
                return(BadRequest());
            }

            var errWrs = await _context.ErrWrs.FindAsync(id);

            if (errWrs == null)
            {
                return(NotFound());
            }
            else
            {
                string dbPath = await SavePlanAsync(plans);

                errWrs.Drawing      = dbPath;
                errWrs.DateReported = DateTime.Now;
                errWrs.Reported     = true;
            }

            _context.Entry(errWrs).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                var     obj     = "New Parts Reported";
                var     content = $"Please to check the new reported part {errWrs.SwsPn} for MH registration";
                var     emails  = new string[] { "*****@*****.**" };
                Message message = new Message(emails, obj, content);
                _emailSender.SendEmail(message);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ErrWrsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            // var notReportedErrors = await GetErrWrsNotReported();
            return(errWrs);
        }
Ejemplo n.º 2
0
        public async Task <Users> Register(Users user, string password)
        {
            byte[] passwordHash, salt;
            CreatePasswordHash(password, out passwordHash, out salt);
            user.Password = passwordHash;
            user.Salt     = salt;

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            return(user);
        }