public static GroupPhoneDto Get(GroupPhone roupPhone) { return(new GroupPhoneDto() { Id = roupPhone.Id, Name = roupPhone.Name }); }
public async Task <Result <bool> > DeleteGroupPhoneAsync(User user, GroupPhone groupPhone) { if (!user.Abonents.Any(a => a.Phones.Any(p => p.GroupPhone == groupPhone))) { user.RemoveGroupPhone(groupPhone); await db.SaveChangesAsync(); return(Result <bool> .Success(true)); } return(Result <bool> .Success(false)); }
private Result <bool> CreateGroupPhone(User user, string str) { Result <GroupPhone> group; group = GroupPhone.Create(str); if (group.Succeeded) { if (user.AddGroupPhone(group.Value).Succeeded) { return(Result <bool> .Success(true)); } return(Result <bool> .Success(false)); } return(Result <bool> .Success(false)); }
public async Task <Result <bool> > AddPhoneAsync(Abonent abonent, GroupPhone phoneGroup, string number) { if (!abonent.Phones.Any(p => p.Number == number)) { var newPhone = Phone.Create(phoneGroup, number); if (newPhone.Succeeded) { abonent.AddPhone(newPhone.Value); await db.SaveChangesAsync(); return(Result <bool> .Success(true)); } return(Result <bool> .Fail(newPhone.Errors)); } return(Result <bool> .Fail(new string[] { "Such Phone exists" })); }
public async Task <Result <bool> > AddGroupPhoneAsync(User user, string name) { if (!user.Groups.Any(g => g.Name == name)) { var newGroupPhone = GroupPhone.Create(name); if (newGroupPhone.Succeeded) { user.AddGroupPhone(newGroupPhone.Value); await db.SaveChangesAsync(); return(Result <bool> .Success(true)); } return(Result <bool> .Fail(newGroupPhone.Errors)); } return(Result <bool> .Fail(new string[] { "Such GroupPhone exists" })); }
public Result <PhoneDto> GetPhone(Abonent abonent, GroupPhone phoneGroup, string number) { var address = abonent.Phones.FirstOrDefault(g => g.GroupPhoneId == phoneGroup.Id && g.Number == number); if (address != null) { return(Result <PhoneDto> .Success(new PhoneDto() { Id = address.Id, AbonentId = address.AbonentId, GroupPhoneId = address.GroupPhoneId, Number = address.Number })); } return(Result <PhoneDto> .Fail(new string[] { "Phone not found" })); }
public async Task <Result <bool> > UpdatePhoneAsync(Abonent abonent, int phoneId, GroupPhone groupPhone, string number) { if (!abonent.Phones.Any(p => p.Number == number && p.Id != phoneId)) { var answer = abonent.UpdatePhone(phoneId, groupPhone, number); if (answer.Succeeded) { await db.SaveChangesAsync(); return(Result <bool> .Success(true)); } return(Result <bool> .Fail(answer.Errors)); } return(Result <bool> .Fail(new string[] { "Such Phone exists" })); }