Example #1
0
 public bool Delete(int eventUserId)
 {
     return(_event.Delete(eventUserId));
 }
Example #2
0
        public bool Edit(ManageEventModel model)
        {
            using (var scope = new TransactionScope())
            {
                try
                {
                    model.Image = Cdn.Base64ToImageUrl(model.Image);
                    var groupId = _event.Edit(new EventModel()
                    {
                        Image        = model.Image,
                        Title        = model.Title,
                        Message      = model.Message,
                        CreatedBy    = model.UserId,
                        DateTime     = model.DateTime,
                        EntityId     = model.EntityId,
                        EntityTypeId = model.EntityTypeId,
                        OccationId   = model.OccationId
                    });

                    #region User management

                    var existedUsers = _eventUser.GetAllUsers(model.EventId);
                    var newUsers     = model.Users.Select(x => x.UserId).ToList();
                    foreach (var user in model.Users)
                    {
                        if (!existedUsers.Contains(user.UserId))
                        {
                            _eventUser.Add(new EventUserModel()
                            {
                                UserId    = user.UserId,
                                CreatedBy = model.UserId,
                            });
                        }
                        else
                        {
                            _eventUser.UpdateRole(new UpdateRoleModel()
                            {
                                UserId  = user.UserId,
                                GroupId = model.EventId,
                                RoleId  = user.RoleId
                            });
                        }
                    }

                    foreach (var item in existedUsers)
                    {
                        if (!newUsers.Contains(item))
                        {
                            _eventUser.Delete(model.EventId, item);
                        }
                    }

                    #endregion

                    #region Group Management

                    var existedGroups = _eventGroup.GetGroupIds(model.EventId);

                    foreach (var group in model.Groups)
                    {
                        if (!existedGroups.Contains(group))
                        {
                            _eventGroup.Add(new EventGroupModel()
                            {
                                EventId   = model.EventId,
                                GroupId   = group,
                                CreatedBy = model.UserId,
                            });
                        }
                    }

                    foreach (var item in existedGroups)
                    {
                        if (!model.Groups.Contains(item))
                        {
                            _eventGroup.Delete(model.EventId, item);
                        }
                    }

                    #endregion


                    scope.Complete();

                    return(groupId);
                }
                catch (Exception ex)
                {
                    scope.Dispose();
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    string json             = js.Serialize(model);
                    Log.Error("BL-Group - Edit" + json, ex);
                    throw new ReturnExceptionModel(new CustomExceptionModel()
                    {
                        StatusCode = HttpStatusCode.BadRequest, Message = ex.Message
                    });
                }
            }
        }