public IHttpActionResult GetGroupList() { try { if (HttpContext.Current.User.Identity.IsAuthenticated) { var groupList = _groupAccountContext.GetGroupListByCompanyId(CurrentCompanyId); var groupCollection = new List <GroupAccountAC>(); var groupAC = new GroupAccountAC(); foreach (var group in groupList) { //it will convert model class to appliation class based on naming conversions. groupAC = ApplicationClassHelper.ConvertType <Group, GroupAccountAC>(group); groupAC.GroupId = group.Id; groupAC.HasBalanced = group.HasBalanced; groupAC.UnderId = @group.UnderId ?? 0; groupCollection.Add(groupAC); } return(Ok(groupCollection)); } return(BadRequest()); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
public Group SaveGroup(GroupAccountAC group) { try { //check the same gorup name is exists or not int groupCount = _groupContext.Fetch(x => x.GroupName == @group.GroupName && x.CompanyId == 0).Count() == 1 ? 1 : _groupContext.Fetch(x => x.GroupName == @group.GroupName && x.CompanyId == group.CompanyId).Count(); if (groupCount != 0) { throw new ArgumentException("The entered group name already exists"); } var groups = new Group { GroupName = group.GroupName, UnderId = group.UnderId, CreatedDateTime = DateTime.UtcNow, CompanyId = group.CompanyId }; _groupContext.Add(groups); _groupContext.SaveChanges(); return(groups); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
public IHttpActionResult UpdateGroup(GroupAccountAC group) { try { group.CompanyId = CurrentCompanyId; var groupDetail = _groupAccountContext.UpdateGroup(group); return(Ok(groupDetail)); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
public IHttpActionResult SaveGroup(GroupAccountAC group) { try { group.CompanyId = CurrentCompanyId; var groupDetails = _groupAccountContext.SaveGroup(group); //it will convert model class to appliation class based on naming conversions. group = ApplicationClassHelper.ConvertType <Group, GroupAccountAC>(groupDetails); group.GroupId = groupDetails.Id; return(Ok(group)); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
public Group UpdateGroup(GroupAccountAC groupAccount) { try { //check that same gorup name exists or not int groupCount = _groupContext.Fetch(x => x.Id != groupAccount.GroupId && x.GroupName == groupAccount.GroupName && x.CompanyId == 0).Count() == 1 ? 1 : _groupContext.Fetch(x => x.Id != groupAccount.GroupId && x.GroupName == groupAccount.GroupName && x.CompanyId == groupAccount.CompanyId).Count(); if (groupCount != 0) { throw new ArgumentException("The entered group name already exists"); } var groupdetail = _groupContext.GetById(groupAccount.GroupId); groupdetail.GroupName = groupAccount.GroupName; groupdetail.UnderId = groupAccount.UnderId; groupdetail.ModifiedDateTime = DateTime.UtcNow; _groupContext.Update(groupdetail); _groupContext.SaveChanges(); return(groupdetail); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }