示例#1
0
        public ApplicationUserDTO Post([FromBody] UserAccessMappingRequest data)
        {
            ApplicationUser current = ApplicationUser.NewApplicationUser();

            data.User.UpdatedBy = CurrentUserID;
            current.CustomSave(data, MD5Generator.ToMD5Hash(data.User.Password));
            var userDto = ApplicationUser.GetByApplicationUserID(current.ApplicationUserID).CurrentDTO;

            if (data.IsFinAdmin && data.User.ApplicationUserID <= 0)
            {
                FinAdministrator fad;
                DateTime         CurrentTime = DateTime.Now;

                if (data.FinAdminId <= 0)
                {
                    fad                = FinAdministrator.NewFinAdministrator();
                    fad.CreatedOn      = CurrentTime;
                    fad.CreatedBy      = CurrentUserID;
                    fad.IsActive       = true;
                    fad.AddressID      = userDto.PhysicalAddressID;
                    fad.Name           = $"{data.User.FirstName} {data.User.LastName} {userDto.ApplicationUserID}";
                    fad.IsOrganisation = false;
                    fad.Email          = data.User.EmailAddress;
                }
                else
                {
                    fad = FinAdministrator.GetByFinAdministratorID(data.FinAdminId);
                }

                var finUsers = FinAdministratorAppUser.NewFinAdministratorAppUser();
                finUsers.FinAdministratorID = fad.FinAdministratorID;
                finUsers.ApplicationUserId  = userDto.ApplicationUserID;
                finUsers.CreatedOn          = CurrentTime;
                finUsers.CreatedBy          = CurrentUserID;
                finUsers.IsActive           = true;

                fad.FinAdministratorAppUsers.Add(finUsers);
                fad.Save();
            }

            return(userDto);
        }
        public void CustomSave(UserAccessMappingRequest data, string md5Password)
        {
            bool cancel = false;

            OnUpdating(ref cancel);
            data.User.CustomCopyDTO(this);
            if (data.User.ApplicationUserID <= 0)
            {
                data.User.Password = md5Password;
            }
            else
            {
                if (data.IsResettingPassword)
                {
                    data.User.Password = md5Password;
                }
            }



            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[spCFM_ApplicationUser_CustomUpdate]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@p_ApplicationUserID", data.User.ApplicationUserID);
                    if (data.User.ApplicationUserID <= 0)
                    {
                        command.Parameters["@p_ApplicationUserID"].Direction = ParameterDirection.Output;
                    }

                    command.Parameters.AddWithValue("@p_LoginName", data.User.LoginName);
                    command.Parameters.AddWithValue("@p_Password", data.User.Password);
                    command.Parameters.AddWithValue("@p_FirstName", data.User.FirstName);
                    command.Parameters.AddWithValue("@p_LastName", ADOHelper.NullCheck(data.User.LastName));
                    command.Parameters.AddWithValue("@p_EmailAddress", ADOHelper.NullCheck(data.User.EmailAddress));
                    command.Parameters.AddWithValue("@p_MobilePhone", ADOHelper.NullCheck(data.User.MobilePhone));
                    command.Parameters.AddWithValue("@p_WorkPhone", ADOHelper.NullCheck(data.User.WorkPhone));
                    command.Parameters.AddWithValue("@p_IsActive", data.User.IsActive);
                    command.Parameters.AddWithValue("@p_PasswordResetNeeded", data.User.PasswordResetNeeded);
                    command.Parameters.AddWithValue("@p_PasswordResetToken", ADOHelper.NullCheck(data.User.PasswordResetToken));
                    command.Parameters.AddWithValue("@p_PasswordResetTokenExpiry", ADOHelper.NullCheck(data.User.PasswordResetTokenExpiry));
                    command.Parameters.AddWithValue("@p_MustChangePassword", data.User.MustChangePassword);
                    command.Parameters.AddWithValue("@p_ApplicationRoleID", ADOHelper.NullCheck(data.User.ApplicationRoleID));

                    command.Parameters.AddWithValue("@p_StatementDeliveryOptionID", ADOHelper.NullCheck(data.User.StatementDeliveryOptionID));

                    command.Parameters.AddWithValue("@p_SameAsPhysicalAddress", data.User.SameAsPhysicalAddress);

                    command.Parameters.AddWithValue("@p_IsResettingPassword", data.IsResettingPassword);

                    command.Parameters.AddWithValue("@p_ActionBy", ADOHelper.NullCheck(data.User.UpdatedBy));
                    AddAddressParams(command, data.PhysicalAddress, "Physical");
                    AddAddressParams(command, data.PostalAddress, "Postal");
                    //command.Parameters.AddWithValue("@p_PhysicalAddressID", ADOHelper.NullCheck(data.User.PhysicalAddressID));
                    //command.Parameters.AddWithValue("@p_PostalAddressID", ADOHelper.NullCheck(data.User.PostalAddressID));
                    command.Parameters.AddWithValue("@p_BusinessAreaIDs", ADOHelper.NullCheck(data.BusinessAreaIDs));
                    command.Parameters.AddWithValue("@p_BusinessDivisionIDs", ADOHelper.NullCheck(data.BusinessDivisionIDs));
                    command.Parameters.AddWithValue("@p_BusinessEntitieIDs", ADOHelper.NullCheck(data.BusinessEntitieIDs));
                    command.Parameters.AddWithValue("@p_HomeIDs", ADOHelper.NullCheck(data.HomeIDs));
                    command.Parameters.AddWithValue("@p_ClientIDs", ADOHelper.NullCheck(data.ClientIDs));


                    //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed.
                    int result = command.ExecuteNonQuery();
                    _applicationUserIDProperty = (System.Int32)command.Parameters["@p_ApplicationUserID"].Value;
                    if (result == 0)
                    {
                        throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
                    }
                }
                //UpdateChildren(this, connection);
                //FieldManager.UpdateChildren(this, connection);
            }

            OnUpdated();
        }