Example #1
0
        public async Task <IHttpActionResult> PuttSalt(int id, tSalt tSalt)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            db.Entry(tSalt).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tSaltExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(tSalt));
        }
Example #2
0
        public async Task <IHttpActionResult> PuttXrefUsersMaritalStatu(int id, tXrefUsersMaritalStatu tXrefUsersMaritalStatu)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tXrefUsersMaritalStatu.ID)
            {
                return(BadRequest());
            }

            db.Entry(tXrefUsersMaritalStatu).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tXrefUsersMaritalStatuExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult EditUser(string id)
        {
            var re     = Request;
            var header = re.Headers;
            var list   = header.ToList();

            try
            {
                var elem = (from item in list where item.Key == "UserAuth" select item.Value).ToList()[0].First();
                var auth = elem.First();
                if (auth != null)
                {
                    if (IDList.Contains(elem))
                    {
                        if (UserCheckRole(elem) == "True")
                        {
                            var    content     = re.Content;
                            string jsonContent = content.ReadAsStringAsync().Result;

                            var Approve       = (from item in list where item.Key == "Approve" select item.Value).ToList()[0].First();
                            var RequestToEdit = db.AllUsers.FirstOrDefault(e => e.ID.ToString() == id);
                            if (Approve == "yes")
                            {
                                RequestToEdit.isApproved = true;
                                db.SaveChangesAsync();
                                return(Ok());
                            }
                            else
                            {
                                RequestToEdit.isApproved = false;
                                db.AllUsers.Remove(RequestToEdit);
                                db.SaveChangesAsync();
                                return(Ok());
                            }
                        }
                        else
                        {
                            return(ResponseMessage(new HttpResponseMessage(HttpStatusCode.Forbidden)));
                        }
                    }
                    else
                    {
                        return(ResponseMessage(new HttpResponseMessage(HttpStatusCode.Unauthorized)));
                    }
                }
                else
                {
                    return(ResponseMessage(new HttpResponseMessage(HttpStatusCode.NotFound)));
                }
            }
            catch (Exception e)
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Unauthorized)));
            }
        }
Example #4
0
        public async Task <HttpResponseMessage> Register([FromBody] User user)
        {
            try
            {
                using (var users = new UsersEntities())
                {
                    var encryptedUser = new User
                    {
                        EmailOrPhone = user.EmailOrPhone,
                        Name         = user.Name,
                        Password     = Encrypt.EncryptPassword(user.Password)
                    };

                    users.Users.Add(encryptedUser);
                    await users.SaveChangesAsync();

                    var message = Request.CreateResponse(HttpStatusCode.Created, encryptedUser);
                    message.Headers.Location = new Uri(Request.RequestUri + user.Id.ToString());
                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public async Task <IHttpActionResult> GetUserPasswordResetCode(tUser user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var users = await db.tUsers.Where(u => u.Email == user.Email && u.AccountStatusID == 1).FirstOrDefaultAsync();

                if (users != null)
                {
                    var userPasswordReset = new tUserPasswordReset
                    {
                        UserID         = users.ID,
                        ExternalUserID = users.ExternalID,
                        ResetCodeID    = Guid.NewGuid(),
                        CreateDateTime = DateTime.Now,
                    };
                    db.tUserPasswordResets.Add(userPasswordReset);
                    await db.SaveChangesAsync();

                    users.tUserPasswordResets.Add(userPasswordReset);

                    return(Ok(users));
                }
                else
                {
                    return(StatusCode(HttpStatusCode.NotFound));
                }
            }
            catch (DbUpdateConcurrencyException ex)
            {
                throw ex;
            }
        }
Example #6
0
        public async Task <HttpResponseMessage> Edit([FromBody] int?id, string name, string address)
        {
            try
            {
                using (var users = new UsersEntities())
                {
                    if (users.Users.FindAsync(id) == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"User {name} does not exist on the database."));
                    }
                    else
                    {
                        users.EditCurrentUser(id, name, address);
                        await users.SaveChangesAsync();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }