public int Add(ManageGroupModel model) { using (var scope = new TransactionScope()) { try { model.Image = Cdn.Base64ToImageUrl(model.Image); var groupId = _group.Add(new GroupModel() { Image = model.Image, Title = model.Title, Message = model.Message, UserId = model.UserId }); foreach (var user in model.Users) { _groupUser.Add(new GroupUserModel() { GroupId = groupId, UserId = user.UserId, CreatedBy = model.UserId, RoleId = user.RoleId }); } scope.Complete(); return(groupId); } catch (Exception ex) { scope.Dispose(); JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(model); Log.Error("BL-Group - Add" + json, ex); throw new ReturnExceptionModel(new CustomExceptionModel() { StatusCode = HttpStatusCode.BadRequest, Message = ex.Message }); } } }
public bool Edit(ManageGroupModel model) { return(_group.Edit(model)); }
public int Add(ManageGroupModel model) { return(_group.Add(model)); }
public bool Edit(ManageGroupModel model) { using (var scope = new TransactionScope()) { try { model.Image = Cdn.Base64ToImageUrl(model.Image); var groupId = _group.Edit(new GroupModel() { Image = model.Image, Title = model.Title, Message = model.Message, UserId = model.UserId, GroupId = model.GroupId, }); var existedUsers = _groupUser.GetAllUsers(model.GroupId); var newUsers = model.Users.Select(x => x.UserId).ToList(); foreach (var user in model.Users) { if (!existedUsers.Contains(user.UserId)) { _groupUser.Add(new GroupUserModel() { GroupId = model.GroupId, UserId = user.UserId, CreatedBy = model.UserId, RoleId = user.RoleId }); } else { _groupUser.UpdateRole(new UpdateRoleModel() { UserId = user.UserId, GroupId = model.GroupId, RoleId = user.RoleId }); } } foreach (var item in existedUsers) { if (!newUsers.Contains(item)) { _groupUser.DeleteUser(new GroupUserIdModel() { UserId = item, GroupId = model.GroupId }); } } 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 }); } } }