Пример #1
0
        public HttpResponseMessage DeleteGroup(int groupId)
        {
            try
            {
                using (BillSplitterEntities entities = new BillSplitterEntities())
                {
                    var entity = entities.Groups.FirstOrDefault(g => g.GroupId == groupId);
                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Group not found. Please try again later"));
                    }
                    else
                    {
                        entities.Groups.Remove(entity);
                        entities.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Пример #2
0
        public HttpResponseMessage UpdateGroupInfoById([FromBody] Group grp)
        {
            try
            {
                using (BillSplitterEntities entities = new BillSplitterEntities())
                {
                    var entity = entities.Groups.FirstOrDefault(g => g.GroupId == grp.GroupId);
                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Group not found. Please try again later"));
                    }
                    else
                    {
                        entity.GroupName = grp.GroupName;
                        entities.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public HttpResponseMessage UpdateUserDetails(int grpId, [FromBody] GroupUser grpUser)
        {
            try
            {
                using (BillSplitterEntities entities = new BillSplitterEntities())
                {
                    var userEntity = entities.GroupUsers.Where(g => g.GroupId == grpId).ToList().FirstOrDefault(u => u.GroupUserId == grpUser.GroupUserId);
                    if (userEntity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Group/User not found"));
                    }
                    else
                    {
                        userEntity.UserName    = grpUser.UserName;
                        userEntity.DisplayName = grpUser.DisplayName;
                        userEntity.Comment     = grpUser.Comment;
                        userEntity.GroupId     = grpUser.GroupId;

                        entities.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK, userEntity));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public HttpResponseMessage DeleteGroupUser(int grpId, int grpUserId)
        {
            try
            {
                using (BillSplitterEntities entities = new BillSplitterEntities())
                {
                    var userEntity = entities.GroupUsers.Where(g => g.GroupId == grpId).ToList().FirstOrDefault(u => u.GroupUserId == grpUserId);
                    if (userEntity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Group/User not found"));
                    }
                    else
                    {
                        entities.GroupUsers.Remove(userEntity);
                        entities.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public HttpResponseMessage Post(int groupId, [FromBody] GroupUser grpUser)
        {
            try
            {
                using (BillSplitterEntities entites = new BillSplitterEntities())
                {
                    entites.GroupUsers.Add(grpUser);
                    entites.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Пример #6
0
        public HttpResponseMessage CreateGroup([FromBody] string groupName)
        {
            try
            {
                using (BillSplitterEntities entities = new BillSplitterEntities())
                {
                    Group grp = new Group()
                    {
                        GroupName = groupName, CreatedOn = DateTime.Now, CreatedBy = "Admin"
                    };

                    entities.Groups.Add(grp);
                    entities.SaveChanges();

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