public AppAssigneeDetailDTO Edit(AppAssigneeDetailDTO model)
        {
            if (model.AppType == "TRL")
            {
                if (model.OrgPositionType == "Manager")
                {
                    model.ListOfBranches = null;
                }
                else
                {
                    model.BranchId = Guid.Empty;
                }
            }
            model.Id = DataService.Add <AppAssignee>(model);

            DataService.SaveChanges();

            var assigneeBranches = DataService.GetEntity <AppAssigneeBranch>(x => x.AssigneeId == model.Id);

            foreach (var x in assigneeBranches)
            {
                DataService.Remove(x);
            }

            if (model.AppType == "TRL")
            {
                if (model.OrgPositionType == "Manager")
                {
                    DataService.Add(new AppAssigneeBranch
                    {
                        AssigneeId = model.Id,
                        BranchId   = model.BranchId.Value
                    });
                }
                else
                {
                    model.ListOfBranches?.ForEach(branchId => DataService.Add(new AppAssigneeBranch
                    {
                        AssigneeId = model.Id,
                        BranchId   = branchId
                    }));
                }
            }
            else
            {
                model.ListOfBranches?.ForEach(branchId => DataService.Add(new AppAssigneeBranch
                {
                    AssigneeId = model.Id,
                    BranchId   = branchId
                }));
            }

            DataService.SaveChanges();

            return(model);
        }
        public async Task <AppAssigneeDetailDTO> Edit(Guid?id, IDictionary <string, string> paramList)
        {
            paramList.TryGetValue("appId", out var strAppId);
            paramList.TryGetValue("AppSort", out var sort);
            paramList.TryGetValue("AppType", out var type);

            var appId = new Guid(strAppId);
            AppAssigneeDetailDTO model;

            if (id == null)
            {
                model = new AppAssigneeDetailDTO();
                if (type == "PRL" || type == "IML")
                {
                    model.OrgPositionType = "Authorized";
                }
                else if (type == "TRL")
                {
                    model.AppType = type;
                }
            }
            else
            {
                var entityId = Guid.Parse(id.ToString());
                model = DataService.GetDto <AppAssigneeDetailDTO>(dto => dto.Id == entityId).Single();
                if (type == "TRL")
                {
                    model.AppType = type;
                }
            }

            if (!string.IsNullOrEmpty(sort))
            {
                model.AppSort = sort;
            }


            if (model.OrgPositionType == "Manager")
            {
                model.BranchId = GetSelectedBranches(model.Id).FirstOrDefault();
            }
            else
            {
                model.ListOfBranches = GetSelectedBranches(model.Id).ToList();
            }

            model.appId = appId;
            return(model);
        }
        public async Task <AppAssigneeDetailDTO> EditLicense(AppAssigneeDetailDTO model)
        {
            var assigneeBranches = DataService.GetEntity <AppAssigneeBranch>(x => x.AssigneeId == model.Id).ToList();
            var branches         = DataService.GetEntity <Branch>(x => assigneeBranches.Select(y => y.BranchId).Contains(x.Id)).ToList();
            var branchesToDelete = branches.Where(x => x.IsFromLicense != true).ToList();

            assigneeBranches.Where(x => branchesToDelete.Select(y => y.Id).Contains(x.BranchId)).ToList().ForEach(x => DataService.Remove(x));
            model.ListOfBranches?.ForEach(branchId => DataService.Add(new AppAssigneeBranch
            {
                AssigneeId = model.Id,
                BranchId   = branchId
            }));

            await DataService.SaveChangesAsync();

            return(model);
        }