Exemple #1
0
        public async Task <ActionResult <ErrorPreviewResponse> > Create([FromBody] NewErrorRequest request)
        {
            var user = await db.Users.FirstOrDefaultAsync(x => x.Login == User.Identity.Name);

            var error = new Error
            {
                CreateDate       = DateTime.Now,
                ShortDescription = request.ShortDescription,
                Description      = request.Description,
                State            = Error.StateEnum.New,
                Urgency          = request.Urgency,
                Criticality      = request.Criticality
            };

            db.Errors.Add(error);

            await db.SaveChangesAsync();

            var firstHistoryItem = new ErrorHistory
            {
                Date    = DateTime.Now,
                Action  = ErrorHistory.ActionEnum.Input,
                Comment = "Init",
                UserId  = user.Id,
                ErrorId = error.Id
            };

            db.ErrorHistory.Add(firstHistoryItem);

            await db.SaveChangesAsync();

            return(new ErrorPreviewResponse
            {
                Id = error.Id,
                CreateDate = error.CreateDate,
                ShortDescription = error.ShortDescription,
                State = error.State,
                Urgency = error.Urgency,
                Criticality = error.Criticality
            });
        }
Exemple #2
0
        public async Task <ActionResult <UserResponse> > Register([FromBody] RegisterRequest request)
        {
            var user = await db.Users.FirstOrDefaultAsync(x => x.Login == request.Login);

            if (user != null)
            {
                return(StatusCode(400, "User with the login already exists"));
            }
            user = new User
            {
                Login    = request.Login,
                Password = request.Password,
                Name     = request.Name,
                Surname  = request.Surname
            };
            db.Users.Add(user);
            await db.SaveChangesAsync();

            await Authenticate(request.Login);

            return(new UserResponse {
                Name = user.Name, Surname = user.Surname
            });
        }