DocSas/PropertyService.Domain/ModelView/Staffs/StaffProvider.cs
/// <summary>
/// save staff as an asynchronous operation.
/// </summary>
/// <param name="staffVM">The staff vm.</param>
/// <returns>Task&lt;DSCResponse&gt;.</returns>
save staff as an asynchronous operation.
save staff as an asynchronous operation .
public async Task<DSCResponse> SaveStaffAsync(StaffVM staffVM)
        {
            var msg = new Dictionary<string, string>();
            var response = new DSCResponse();
            var issuccess = false;
            if (staffVM.Id == Guid.Empty)
            {
                var management = await _appCommon.GetManagementUserAsync(staffVM.CreatorUserId);
                if (management != null)
                {
                    var users = await _appCommon.GetUserByCodesAsync(staffVM.serviceCodeValues);
                    var staffs = new List<Staff>();
                    foreach (var item in users)
                    {
                        staffs.Add(new Staff() { UserId = item.Id, ManagementUserId = management.Id, Title = staffVM.Title, IsValid = true, AddedDateUtc = DateTime.UtcNow, ModifiedDateUtc = DateTime.UtcNow });
                    }
                    await _staffRepo.AddAsync(staffs);
                    issuccess = true;
                }              
            }
            else
            {
                var staff = await _staffRepo.GetSingleAsync(x => x.Id == staffVM.Id);
                if (staff != null)
                {
                    staff.Title = staffVM.Title;
                    await _staffRepo.ModifyAsync(staff);
                   issuccess = true;
                }
            }
            response.ResponseData = issuccess;
            response.ErrorMessage = msg;
            return response;
        }
public async Task < DSCResponse > SaveStaffAsync ( StaffVM staffVM ) { var msg = new Dictionary < string , string > ( ) ; var response = new DSCResponse ( ) ; var issuccess = false ; if ( staffVM . Id == Guid . Empty ) { var management = await _appCommon . GetManagementUserAsync ( staffVM . CreatorUserId ) ; if ( management != null ) { var users = await _appCommon . GetUserByCodesAsync ( staffVM . serviceCodeValues ) ; var staffs = new List < Staff > ( ) ; foreach ( var item in users ) { staffs . Add ( new Staff ( ) { UserId = item . Id , ManagementUserId = management . Id , Title = staffVM . Title , IsValid = true , AddedDateUtc = DateTime . UtcNow , ModifiedDateUtc = DateTime . UtcNow } ) ; } await _staffRepo . AddAsync ( staffs ) ; issuccess = true ; } } else { var staff = await _staffRepo . GetSingleAsync ( x => x . Id == staffVM . Id ) ; if ( staff != null ) { staff . Title = staffVM . Title ; await _staffRepo . ModifyAsync ( staff ) ; issuccess = true ; } } response . ResponseData = issuccess ; response . ErrorMessage = msg ; return response ; }
save staff as an asynchronous operation.
save staff as an asynchronous operation .
None
staffVM
StaffVM
The staff vm.
The staff vm .